Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Is there anything to catch me if I fall into the void? Are there limits I can set for the world?

Discussion in 'Editor & General Support' started by Marscaleb, Sep 13, 2020.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,036
    If I have a player or other object in my scene fall outside the normal play area, and thus will have no ground under it ever, is there any kind of limit in Unity that I can set to delete or kill the object so it doesn't just fall into infinity?
    (And if not, what WOULD happen if I really let it fall as far as it could? Numbers may be infinite but computer variables are not. Eventually it will hit a limit of what Unity can properly store as a value for a location. Will it crash? Will it roll over to the opposite extreme value? Will it start corrupting adjacent values in memory?)

    But moreover I'm just thinking: I'd like to be able to account for objects that manage to fall out of the world, and while I could add code to my objects that continually checks to see if they've gone past some arbitrary value, it honestly seems to me like this is something that should be coded into the engine itself, like a property built-in to GameObject.

    Like I recall that in UT maps there is a value in the map property for a KillZ, and any player/missile/whatever that ever falls beneath that value is automatically killed. Is there some property in my scene or project where I can set absolute limits so that if anything ever travels too far it can be dealt with?
    And is there any way to specify how said object is dealt with? Like most common objects I would just want to destroy, but if its a player I'd want to call my killPlayer function so the game doesn't break down because stuff cant find the player anymore.

    So yeah, is there such a thing built in to Unity?
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    The simplest solution is probably to just add a Collider somewhere out-of-bounds that spans the entire map and destroys any object it collides with via
    OnTriggerEnter
    .
    No need to continuously check the object's position every frame.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,753
    Yeah I would say virtual floor / wall should be good. Or for things like missiles and bullets, life duration. So they get killed after let's say 5 seconds.
     
  4. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,036
    Those are good methods; I'm not going to argue against that. But I'm just wondering if there is any kind of fail-safe built in to the engine itself; ideally something that would work more reliably and/or more efficiently than a self-created method.
    After all, bugs happen.
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,943
    No, because the engine has no way of knowing if this is a bug, nor any way of knowing how to handle it in a way that works for your game. If this were going to be handled for you it would be the job of a framework like you would find on the store as it would have been made with an understanding of whether it's a bug and how to handle it properly.
     
    Last edited: Sep 14, 2020
  6. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,036
    I'm talking about having a setting within the engine. You'd set it to whatever the limits for your game should be.

    Presumably the default would be the absolute limits the engine could handle, or possibly just turned off.

    It could just call a method to GameObject, something like "OnWorldLimitHit" and it could carry a default value of calling Destroy on the game object, and designers could just write their own override for the function for classes/objects that need to be handled differently.

    At least, that's how I would set it up if I were making this engine. But of course, the Unity devs tend to pursue things differently than I do.
     
    Last edited: Sep 14, 2020