MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

Instantiating a Clone w/ TapToPlace as a Component

Open mattfedocsg opened this issue 9 years ago • 2 comments

I am not sure if this is "by design", but if you have an object that has TapToPlace.cs added as a component, with a saved friendly anchor name specified and then go to instantiate a clone, the clones position and anchor matches that of the original object. Even if you try to instantiate the object with a new pos and rot. I assume because the position is saved by anchor.

I fixed this on my end by instantiating the object, changing the anchor name, attaching the anchor to the WorldAnchorManager, then changing the position and rotation.

I feel like the script should have done this for me though. Maybe check to see if the world anchor store already has that key anchor name? Then at on destroy remove the anchor that was cloned?

I guess it is just my opinion, but anyone else have any thoughts? Or maybe I am missing something? Thanks!

mattfedocsg avatar Mar 15 '17 11:03 mattfedocsg

If anyone is having issues with this, I've just been updating the friendly name with the date down to the second or millisecond that the object was instantiated. Then, in best gaming practice, throw that object in a pool. So instantiate the object with a new position, change the anchor name, and attach the anchor. Done.

GameObject gameObject= GameObject.Instantiate(OriginalObject, pos, rot);

gameObject.GetComponent<TapToPlace>().SavedAnchorFriendlyName = "gameObject_" + System.DateTime.Now.ToString("yyyyMMddhhmmss");

WorldAnchorManager.Instance.AttachAnchor(gameObject, gameObject.GetComponent<TapToPlace>().SavedAnchorFriendlyName);

mattfedocsg avatar Mar 21 '17 16:03 mattfedocsg

@mattfedocsg With the latest PR You would just need to make sure the GameObject names are unique.

StephenHodgson avatar Jun 27 '17 21:06 StephenHodgson