Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Additive Scene Loading with Offset

Discussion in 'Unity 5 Pre-order Beta' started by gilley033, Dec 10, 2014.

  1. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,181
    I am curious how difficult it would be to add new methods for Application.LoadLevelAdditive and Application.LoadLevelAdditiveAsync that allow you to specify a position offset for the objects in the scene.

    With Instantiate, you can specify the position where you wish to load the object, so there appears to be some behind the scenes way to modify the position of the object before it is "integrated" into the current scene.

    Of course, a scene can consist of many "root" objects at different positions, so it doesn't make sense to specify a position like with Instantiate. This is why I recommend an offset value, which can be applied to all of the top level root objects in the scene to effectively move the entire scene to a new location in the game world.

    You may be wondering why this is necessary. Mainly, I'm interested in this for creating large streaming (possibly repeating) worlds. With large worlds, one strategy to avoid floating point issues is to move the entire world back to the origin at certain times. This requires variable positions for the pieces of the world (each piece is a scene).

    Moving the objects in the scene post-load is possible, and indeed I already do this. However, it would be more efficient and simpler to just have Unity change the position before the objects are integrated into the main scene.

    So again I ask, would this be possible? I can't imagine it would be too hard to implement if it is possible.
     
  2. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    This would definitely be a useful feature, and has long been requested. As I understand it, one of the main issues (but not the only one) is that many of the advanced features like occlusion culling, navigation, and static batching rely on world-space coordinates. Could be totally wrong on that though.
     
  3. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,181
    Ahh I see, that makes sense. Sounds like it's not something that will be implemented any time soon then. Oh well.
     
  4. Immanuel-Scholz

    Immanuel-Scholz

    Joined:
    Jun 8, 2013
    Posts:
    221
    instead of just modify the transorm.position/rotation, I would love to have a way of "pre-initializing" any object, then get a callback when they are created but not "integrated" and then another function to finally "integrate".

    Something like that:

    Code (csharp):
    1.  
    2. // no awake for any component of this object is called yet.
    3. // Its just barely constructed and filled with serialized values (or copied values in case of Object.Instantiate)
    4. void PreAwake()
    5. {
    6.     transform.position = xxx;
    7.     GetComponent<MyComp>().someValue = 42; // "MyComp" never sees any other value than 42, even in its Awake()
    8. }
    9.  
    10. ...
    11.  
    12. // way of "precreating" any object
    13. var o = (GameObject)Object.BeginInstantiate(prefab);
    14. o.GetComponent<RigidBody>().mass *= 2; // rigidbody is only ever instantiated with double mass.
    15. Object.FinializeInstantiate(o);
    16.  
    Up to now, I have to change the prefab before Instantiate (and change it back after) to achieve this kind of pre-initialize effect. Very nasty.


    If you have this, then an "void OnPreLevelLoaded()" global callback should be easy to add...?


    On the other hand... a feature like this can easily mess up a lot of multi-threading optimizations for built-in components... So consider it a "mild suggestion". ;)
     
  5. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    Yup, you guessed, it easy to do. I can see people more often asking for features that can be easly done by themselves. I mean, where it can go, someone will ask for automatic game making method!? come on guys, don't be lazy. Asking for features is not bad at all, but if you can do it, then do it, don't ask for automatic "X" method...
     
  6. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,181
    Moving the objects in a scene post load is the only possibility currently, and it carries performance implications. Moving objects pre load, which is what I am talking about here, is only possible if you have access to the source.

    Just because I said I thought it would be easy to implement (which in hindsight was a stupid statement) doesn't mean I would be able to do it myself. As stated, that is simply impossible.
     
  7. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    Nope, you can load disabled objects, move them, and then enable them. When objs are disabled, they don't exist in physx calculations.
     
  8. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,181
    Good point. Still, you can't tell me things wouldn't be better with the ability to alter a scene's position pre-load.

    Could you imagine if you couldn't specify a position with Instantiate, and instead had to load an object, move it, and then enable it?

    If you read the original post, you'll see that I didn't make any demands that they include this feature; I merely questioned how hard it would be to implement. I'll accept deram_scholzara's answer in that regard.