FOVE SUPPORT CENTER

Camera drop between scenes - Unity

Answered

Comments

2 comments

  • Official comment
    Avatar
    jeremy

    Hey Sam,

    Thanks for sharing your solution, I will mark it answered to increase the chances of it being seen by others as such.

    Regards,

  • Avatar
    Sam Collins

    I actually figured out a workaround on my own. In case anyone else is having this issue, I'll post it here:

     

    • Create an empty GameObject, we'll call it "Fove Container".
    • Ensure that this GameObject is not destroyed when a new scene loads, using DontDestroyOnLoad().
    • Instantiate a Fove Rig 2(or Fove Rig) from the prefab with the Fove Container as its parent, using Instantiate().
    • Now the camera will be maintained across scenes.

    Here is the code:

    (I use a few extra lines to make sure only one camera ever exists - not always necessary but good practice)

    * Link the Fove Rig 2 prefab to FIPrefab. Attach this script to the Fove Container.

    using UnityEngine;

    public class SpawnFove : MonoBehaviour {

    public GameObject FoveRigPrefab;
    public static DontDestroy cam;

    void Awake()
    {
    // Check if cam exists
    // If not, ensure it does not get destroyed
    // Otherwise, destroy cam
    if (cam == null)
    {
    DontDestroyOnLoad(gameObject);
    cam = this;
    }
    else if (cam != this)
    {
    Destroy(gameObject);
    }

    // Instantiate the Fove Rig 2 prefab
    Instantiate(FoveRig2Prefab, transform, false);
    }
    }

     

     

Please sign in to leave a comment.