flutter-unity-arkit-demo
flutter-unity-arkit-demo copied to clipboard
How to place an existing gameObject in AR Scene?
Instead of dragging prefab into the inspector and instantiating it, how can I place a gameObject in AR scene.
Below is my code:
[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;
}
}
Hi, @Linspirit98 It would be really great if you can be more specific about your question...Maybe you can explain using an example scenario.
Hi, @Linspirit98 It would be really great if you can be more specific about your question...Maybe you can explain using an example scenario.
Hi. 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?
Best regards.