Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Instantiated objects are not fixed in my scene

Discussion in 'AR' started by eco_bach, Feb 15, 2021.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    There is something I am not fully grasping about instantiating new objects in an AR Scene.

    I've created a simple Plane Prefab and then defined it as "_wallPrefab".
    I've also created a reference to my AR Session Origin Game Object as "_arOrigin"

    This is my creation code. But when I run this my instantiated prefab is always relative to the camera instead of being fixed in World or session space. Why is this happening? Also is it necessary to parent instantiated objects to your session origin?

    Code (CSharp):
    1. public void CreateObjects(float w = 1.0f, float l = 1.0f, float h = 0.1f)
    2.     {    
    3.         Vector3 pos = new Vector3(.5f, 0, -0.5f);//arbitrary values to position in scene
    4.         Quaternion rot = new Quaternion(0, 0, 0, 1);
    5.         _wallObject = Instantiate(_wallPrefab, pos, rot,_arOrigin.transform);
    6.         _wallObject.transform.localScale = Vector3.Scale(transform.localScale, new Vector3(w,h,l));
    7.     }
    Update- the issue seems to be my mesh. Simply changing the MeshFilter mesh in my placed Prefab from either Cube or Quad to Plane breaks it. ie a Plane mesh cannot be 'anchored' in a scene. Why?
     
    Last edited: Feb 16, 2021