Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to position a additive loaded scene within current scene,

Discussion in '2D' started by Diluision88, May 4, 2020.

  1. Diluision88

    Diluision88

    Joined:
    Apr 5, 2020
    Posts:
    10
    Hi all,

    I am currently loading a scene additivley into my current scene when a player approaches a terminal screen to give the illusion that a computer screen comes into view, I have figured out how to do this but the issue I am encountering is that at the moment the scene which is being added to my current scene lays directly over the top of my current scene causing lots of collider issues. I have bodged a way around this by just creating each "terminal" scene offset on the X axis so that it loads off screen and the camera locks to it, however I feel this could cause problems down the line when I am making larger levels.

    Basically what I am wondering is if there is anyway to decide exactly where in the current scene the new scene is loaded and if so would someone be able to give me an example of how to go about this?

    Thanks
     
  2. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    883
    Hello @Diluision88 ,
    Like you have already experienced, scenes doesn't come with an offset. It sounds like using prefab(s) would be a better fit. Have you tried using prefabs for this scenario?
     
  3. Diluision88

    Diluision88

    Joined:
    Apr 5, 2020
    Posts:
    10
    I haven't tried prefabs as I wasn't sure that was a possibility as I am still quite new to coding and unity, is it possible to load a whole scene as a prefab?
     
  4. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    883
    So prefabs are great when you have one or more GameObjects that you would like to re-use/spawn dynamically during runtime. Have a look at the manual for some more examples: https://docs.unity3d.com/Manual/Prefabs.html
     
  5. Diluision88

    Diluision88

    Joined:
    Apr 5, 2020
    Posts:
    10
    I have been attempting to implement this into my game and am current stuck with an issue. I can instantiate the level prefab (which is all contained within a single game object as children). The level is placed at the correct x,y but anything that has code pertaining to object movement etc are offset from the actual instantiate (things like the player, moving platforms are all stuck in space between the actual level and the instantiate).

    Shouldn't they take their x,y position based on the parent empty game object rather than the currently loaded levels game space?
     
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    883
    Do I understand your issue correctly that static game objects are positioned correctly, but game objects being moved are positioned at the wrong position?

    If that is the case, I think the issue might be in the movement code. Maybe it caches an incorrect starting position to base the movement off of. Also, make sure you are using
    transform.position
    if you want to move game objects with an absolute position, and
    transform.localPosition
    if you want to move game objects with a relative position to the parent.
     
  7. Diluision88

    Diluision88

    Joined:
    Apr 5, 2020
    Posts:
    10

    That is awesome, thank you for the help. I managed to get it all working as intended now.
     
    Ted_Wikman likes this.