Search Unity

Question Using AR Foundation to load and display scenes instead of prefabs

Discussion in 'AR' started by Dhabia, Nov 23, 2022.

  1. Dhabia

    Dhabia

    Joined:
    Sep 21, 2021
    Posts:
    3
    Is there any guide or tutorial on this? All the tutorials and forums online place prefabs but I would rather have scenes.
     
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    This isn't really an AR-specific question. You would use AR Foundation the same way, then just load a scene via scripting. https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html

    Be mindful that if you use LoadSceneMode.Single, this will destroy the AR Session and XR Origin in your scene. You can use DontDestroyOnLoad if you want to keep the same AR Session and XR Origin, or check out our sample project to see how we handle initializing a new AR Session in every scene.
     
  3. Dhabia

    Dhabia

    Joined:
    Sep 21, 2021
    Posts:
    3
    I am trying to do something like this, but it doesn't work at, |'m unsure why not.

    _scenesList is an array with all of the names of my Scenes.

    Code (CSharp):
    1.     private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
    2.     {
    3.         foreach(var TrackedImage in eventArgs.added){
    4.             Debug.Log(TrackedImage.name);
    5.             var imageName = TrackedImage.referenceImage.name;
    6.             //for loop to look through the list of images and the equivalent
    7.             for(int i =0; i<numberOfScenes; i++){
    8.                 //I have to make a lot of if statements here (one for each scene lol)
    9.                 if (imageName==_scenesList[i])
    10.                 {
    11.                     SceneManager.LoadScene(_scenesList[i]);
    12.                     Debug.Log(TrackedImage.name);
    13.                 }
    14.             }
    15.         }
     
    Last edited: Nov 27, 2022
  4. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    What is the issue you are experiencing?
     
  5. Dhabia

    Dhabia

    Joined:
    Sep 21, 2021
    Posts:
    3
    The Scene doesnt load in
     
  6. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    If your scene isn't loading, it's likely that your SceneManager.LoadScene call is not executing. Does your Debug.Log statement print?