Search Unity

Multiple Cameras over separate scenes

Discussion in 'Cinemachine' started by tbrowwnnn, Jul 6, 2018.

  1. tbrowwnnn

    tbrowwnnn

    Joined:
    Feb 8, 2018
    Posts:
    2
    Hi there, Im pretty new to Unity and Cinemachine and am just looking for a bit of help.

    Im currently figuring out how to move from one scene to another without losing information when switching between scenes. Instead of using the dont destroy on load method I've been using the additive method where I make my player its own scene. This way I can keep rules and hud options across multiple scenes.

    However, the problem I run into is with the camera. If I put a virtual camera on my scene that my player has loaded into it cannot follow the player since its in its own scene.

    This is resolved if I put the vcam with my player scene however I then am not able to confine my camera anymore since my polygon collider is in the level scene. Seeing as every scene has its own collider it would be difficult to put every collider in the game in my players scene.

    This also causes problems with parallaxing as this uses the camera movement and references different backgrounds images in each separate scene.

    Is there any way to reference my player in a separate scene? Thank you in advance.
     
  2. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    Cross-scene dependancies / linking is an area which can definitely cause pain. We're working on a binding component which lets you link things between scenes to help manage this but it's not released yet.

    The big question - why are you using so many different scenes? If you need to contain areas so multiple people can work on then, prefabs are a solid method. They handle version control and let different people work on things at the same time (once they're setup of course).

    Otherwise you'll need to either consider keeping your characters and cameras in the same scene(s).
     
  3. tbrowwnnn

    tbrowwnnn

    Joined:
    Feb 8, 2018
    Posts:
    2
    In all honesty I dont know. Am I supposed to just make my entire game as one giant scene? Wont that be difficult to run or taxing on the computer? I mainly am using scenes to separate my levels and my hub worlds and am trying the figure out the best method to accomplish this.

    I am the only person working on this game so it's not so multiple people can work on it at once, its so I can keep my different tiles and rules compartmentalized and keep the game efficient. If there is a better method then by all means please correct me, I've only been working in unity for about 3 months and have zero background in coding and game development. Any feedback or help is appreciated.
     
  4. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    Environments are a good candidate for separate scenes as they hold the lighting baking information.

    Other than that, it's good to put cameras and characters in the same scene. No performance issues with that.
     
  5. IanItor

    IanItor

    Joined:
    Dec 21, 2017
    Posts:
    12
    The workaround i'm using when working with additive scenes is having core functionality at holder scene and then when i need to turn on some of it at a required scene i compare the build index of a scene at second position in a SceneManager with a build index associated with specific gameobject in a custom info class. Then if the id matches i activate the gameobject and let it do their job.

    I just got another idea: Keep cameras on a separate scenes but move them to your main scene with a SceneManager.MoveGameObjectToScene. But first you have to setup additively loaded scene to be the active one(SceneManager.SetActiveScene), to be able to move gameobject from a current scene. Then set a holder scene back to be active. If you transition to another scene don't forget to destroy that camera since it has no use anymore.
     
    Adam_Myhill likes this.
  6. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    243
    Bump in case there are new solutions now
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Another option is to leave the cameras in separate scenes but when they load you can have a script that dynamically binds them to the player.
     
    concordion2k and Midiphony-panda like this.
  8. kaiming69

    kaiming69

    Joined:
    Apr 19, 2022
    Posts:
    1
    any links or tips as to how u can make this work
     
  9. Vlad_Iliescu

    Vlad_Iliescu

    Joined:
    Nov 1, 2020
    Posts:
    1
    heya there you can have a look at this talk has some cool and good points about scene management and as well you should use the Player as a global variable and just get the camera to look for it and use it
     
    concordion2k likes this.