Mixedrealitytoolkit-unity: WorldAnchors not saving

Created on 23 Jun 2017  路  15Comments  路  Source: microsoft/MixedRealityToolkit-Unity

I tried to implement WorldAnchors into my Project so the next time i start it, the holograms would be at the same position.
When this didn't work, no matter what i did, i started a new Project which just has a cube, the camera, Cursor and the spatial mapping aswell as the worldanchormanager. the cube got the script taptoplace. everything works fine, the room is beeing recognized and i can move the cube to the desired location, but as soon as i restart the app, the cube is in it's original position. What am i doing wrong?

HoloLens Question

Most helpful comment

after quite some hours deep into this problem of mine, i got a solution to work. What i gathered so far is that the WorldAnchorManager doesn't load the worldanchors on startup. it just loads the anchorstore. i don't know if that is a designchoice or if i still don't understand something, but i had to iterate over all anchors stored and assign them to the right objects at the start so that it took it's saved position.

All 15 comments

Im pretty sure the world anchor storage just holds the positional data, not the actual game object, right? It doesnt actually hold the hologram itself. So if you instantiate a new object, it will be destroyed on application destroy, but the anchor will still live in the anchor store. Try re-instantiating the object on load with the anchor store name you saved. It should show up in the right position.

thanks for your fast answer, I'll try that. but after all the scripts in this toolkit already reconnect to the worldanchorstore and try and load the saved anchors when the program is launched. at least when I unsterstood the code behind worldanchormanager.cs and taptoplace.cs

after quite some hours deep into this problem of mine, i got a solution to work. What i gathered so far is that the WorldAnchorManager doesn't load the worldanchors on startup. it just loads the anchorstore. i don't know if that is a designchoice or if i still don't understand something, but i had to iterate over all anchors stored and assign them to the right objects at the start so that it took it's saved position.

@SpycherS, I'm already working on the update to the WorldAnchorManager should have that submitted soon.

@SpycherS I had to do the same things using the GetAllIDs() function to iterate over everything and match it to what I have saved in my game object store. Then I re-instantiated all the prefabs that matched the keys in the anchor store. Still not sure how this will work outside of my single location into other locations. Will the store "know" I am in a different location and therefore not load certain WorldAnchors?

Yeah, it's difficult to know what the game object reference each imported anchor will have. I guess you _could_ name the anchor after each game object, but then you'd need to make sure you're using unique game object names in your scene (which really you should be doing anyway).

@StephenHodgson, yep. Agree 100%. There really is no way around that it seems. I am currently naming my instantiated objects with timestamps down to the second and using that as the anchor name. So when I come back I can just check the anchor store and re-instantiate. Storing it all in SQLite. Using a content management system while youre in gameplay and then just adding the anchor id to your system seems to be the best option. The WorldAnchorStore is doing what is should though for sure.

It should also be exporting, uploading, and downloading anchors from the sharing service too imo. That's actually what I've been working on a bit. Actually thinking about making a base WorldAnchorManager class with two inheriting classes (SharingWorldAnchorManager and UNetWorldAnchorManager), for each multiplayer service type.

@SpycherS & @mattfedocsg , checkout my new PR https://github.com/Microsoft/HoloToolkit-Unity/pull/742 and be sure to enable KeepRoomAlive on the SharingStage.

I have a question about the life cycle of anchor stores. I apologize if the question seems stupid...
When I open my app, it starts with a blank window. By "restarting" the app, do you mean totally close both the hologram and this blank window, or still let the blank window be there?
As I've tried, when I totally close the app and restart it, the anchor seems to be gone and the object is in its initial position.
Is the anchor store attached with each app, or stored in the disk to be used in a long future? Can I still use the anchor store if I reboot the Hololens?
Thanks!

the anchors are persistant even when you close the white window or restart the hololens. for the objects to stay in their place when you just go out of the app but leave the white window open, you don't need anchors, because the app is still open. so the way you described it, it seems like your anchors dont work yet. the anchorstore is only being thrown out when you delete the app from your hololens or load a newer version of the app on it, which also first deinstalls the original app.

I see. Thank you very much @SpycherS !

@spycherS that would be killer. I am looking forward to all the new stuff

@StephenHodgson I'm sorry, but i still don't get the worldanchormanager to work. As i've written, by now i found my own way of saving and loading worldanchors, but it's a dirty way and it doesn't use any of the toolkits scripts. but when i try to use the toolkit, the anchors don't seem to load. since there's not much documentation it might very well be that i'm just missing a part, but could you just explain in a few sentences, what exactly is needed of this toolkit to let's say save the position of a cube in the world? that would actually be very helpful.

I've updated the SharingWorldAnchorManger. let me know if it's still an issue.

Was this page helpful?
0 / 5 - 0 ratings