Search Unity

How to handle very large scenes ?

Discussion in 'Editor & General Support' started by Cheo6, Nov 27, 2020.

  1. Cheo6

    Cheo6

    Joined:
    Nov 20, 2017
    Posts:
    28
    Hello, I recently realized that Unity has a hard time handling kilometers large scenes : when the player is just 1km away from the origin point, the main character starts jittering a bit and aiming with raycasts becomes imprecise (at least that's the case with UCC's crosshairs which flicker when hovering on the edges of an enemy object). These issues become more and more visible the further the player goes, if you get 10km away it's clearly obvious.

    Now the thing is I am not trying to create a gorgeous open world for the moment - what I wish for is to be able to move a character all across a 10km wide plane in an empty scene without any issue. How is it possible to achieve that in Unity ? I heard of a method consisting in moving the origin point instead of the player, but that really sounds impractical. And a guy told me about this asset Sectr : https://assetstore.unity.com/packages/tools/terrain/sectr-complete-2019-144433
    But I'm not sure if this is what I need, can someone who's used it confirm it or suggest me another asset ?
    Hope you can help me with this !
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    As a first step, you could check if you really need this; most games don't, because they simply adjust their reference scale to something smaller or have a loading screen in-between areas (e.g. indoor vs outdoor).

    Secondly, you've probably heard the term "floating point precision", which is affecting your data when numbers become really large or really small. However, that's only an issue if you need both ends of the spectrum. The range is the limiting factor. So, to get 10km working, you could scale down your entire world by a certain factor. If your player is no longer 1m wide, but 10cm, you gain a lot while only losing a little bit of precision in the smaller degrees.

    If you then decide that you really need more precision and larger numbers, the easiest way in Unity is the floating origin point. You would let the player start at the origin and let them walk in a direction for maybe 1km. Take note of the offset from the origin (1000, 500, 0). Then simply move all objects in the game by (-1000, -500, 0) to recenter the player. This resets the precision of the transform values.

    Others have experimented with using doubles instead of floats, but this will only work for custom scripts or some advanced conversion between Unity's float format and their own.
     
    Cheo6 and Kurt-Dekker like this.
  3. Cheo6

    Cheo6

    Joined:
    Nov 20, 2017
    Posts:
    28
    Thank you for your thorough answer, the floating origin point method sounded a bit complicated and exaggerated to me at first, but it's clearly the best solution ! I'll just have to ask on the Opsive forum how to handle it best with UCC, but other than that it's not really complicated ! Thanks again <3