Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
2.98k stars 1.11k forks source link

How to create GameObjects in the same location after applying WorldMap #1053

Closed Maru-prono closed 1 year ago

Maru-prono commented 1 year ago

Hello.

I want to generate arbitrary GameObject between two iPads in the same location each of them using ARWorldMap.

I have successfully serialized WorldMap, communicated, deserialized, and even Apply. But when I create the object after applying WorldMap, it is not created in the same location.

”Same location" means that when a GameObject is generated on a desk taken on one iPad, it is also generated on the desk on the other iPad.

I checked the length and contents of the byte array after serializing the WorldMap, and they were consistent before and after the communication.

In addition, the following code was created for object generation.

         for(int z = 0; z < 3; z++)
         {
                for (int y = 0; y < 5; y++)
                {
                    for (int x = 0; x < 5; x++)
                    {
                        var cap = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                        var pos = new Vector3(0.1f * x, 0.1f * y, 0.1f * z);
                        cap.transform.position = pos;
                        cap.transform.localScale = new Vector3(0.02f, 0.02f, 0.02f);
                        if(pos == Vector3.zero)
                        {
                            cap.GetComponent<Renderer>().material.color = Color.red;
                        }
                    }
                }
            }

Unity:2021.3.3f1 ARFoundation:4.2
iPadOS:16.2(both of them) iPadGen:6th, 2th

Please let me know if you need any further information.

Thanks, Maru

Maru-prono commented 1 year ago

It was necessary to set the anchor to the parent to generate the object.

Instead, you should parent your content to the anchor. https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.0/manual/anchor-manager.html#:~:text=Instead%2C%20you%20should%20parent%20your%20content%20to%20the%20anchor.