Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to place an existing gameObject in AR Scene? #16

Open
Linspirit98 opened this issue Aug 11, 2020 · 0 comments
Open

How to place an existing gameObject in AR Scene? #16

Linspirit98 opened this issue Aug 11, 2020 · 0 comments

Comments

@Linspirit98
Copy link

Linspirit98 commented Aug 11, 2020

Hi, my question is: Instead of dragging prefab into the inspector and instantiating it, how can I place a gameObject in AR scene?

So I would like to load a gameObject from a scene into my AR scene. The AR scene will automatically detect for the plane. Once a plane is detected, the gameObject loaded should be automatically placed on the plane. The code I found uses prefab and instantiate like this

placedObject = Instantiate(placedPrefab, arPlane.transform.position, Quaternion.identity);
However, if the placed prefab is of type gameObject (basically I dragged the gameobject loaded), it didnt work. the gameobject was floating in air instead of following the detected plane. Do you know whether it is possible to achieve my desired scenario? Why is the position of gameobject wrong when I drag an existing gameobject in the scene instead of prefab?

Thank you in advance!

Below is my code but it didnt work:

[SerializeField]
 private GameObject placedPrefab;

 [SerializeField]
 private GameObject placedObject;

 [SerializeField]
 private ARPlaneManager arPlaneManager;

 void Awake() 
 {
     dismissButton.onClick.AddListener(Dismiss);
     arPlaneManager = GetComponent<ARPlaneManager>();
     arPlaneManager.planesChanged += PlaneChanged;
 }

 private void PlaneChanged(ARPlanesChangedEventArgs args)
 {   
     if(args.added != null && placedObject == null)
     {
         ARPlane arPlane = args.added[0];
         //placedObject = Instantiate(placedPrefab, arPlane.transform.position, Quaternion.identity);
         placedPrefab.transform.position = arPlane.transform.position;
     }
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant