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

Open world questions

Discussion in 'World Building' started by epochplus5, Mar 6, 2022.

  1. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    Hi Guys,

    Building an open world type game. Nothing the scale of GTA V lol. But was wondering how important it is to instance things when the player comes into contact with them. EG my player walks down the road and into a bar. There are a few people sitting at the tables with basic scripts changng their animations etc. Should these characters only be instantiated when the player walks in and destroyed when the player leaves again. Im just not sure of Unitys power/scale regarding things like this. It is for Android, so maybe it is neccesary to cut down on processing power. Like to get some thoughts in.
     
  2. theonerm2_unity

    theonerm2_unity

    Joined:
    Sep 7, 2018
    Posts:
    131
    You could pool things like that. Just have a certain amount of characters loaded into memory all the time and pull from the pool when the player goes into the area. That's how I'd do it. You could keep them disabled to save on the GPU/CPU power until you need them. Of course they will still take up memory being disabled though.
     
  3. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    theonerm2_unity thanks for answering, if the world isnt too big and the graphics arent super duper could i just have it all in one scene, or will it definitely suffer down the line?
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,616
    Maybe. Remember that there are also performance implications in instantiating and destroying objects too, so you could end-up making your game slower by doing this. It all depends. Pooling like theonerm2_unity suggests might be a good solution depending on how your game works. The only way to know for certain is to use the profiler and also test on your target hardware.
     
    epochplus5 likes this.
  5. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    I agree with @kdgalla and @epochplus5.

    For my multiuser system, I use lists/arrays to keep references to such actors and I use SetAvtive to enable/disable avatars and vehicles (e.g. when changing vehicles/avatars). I treat it the same as level-of-detail but when you disable something that is also an actor, you need to also manage a flag that tells the system of its status. But you need to do that anyway.

    There is still a cost to using SetActive, but I think it is much less than instantiating. Also, there are performance gains from maintaining the references to objects and not having to recreate them from scratch.

    It is really quite a good question because, in general, maintaining state across the network while maintaining good performance are quite complex issues.
     
    epochplus5 likes this.
  6. Psyonx

    Psyonx

    Joined:
    Dec 28, 2016
    Posts:
    4