Reputation: 1
The idea is simple 'instantiating a map' in Awake with random values.
But the Question is: Should i instantiate the whole map in one frame (using Loop)? or better to instantiate each object per frame?
Because i don't want to ruin player's ram by instantiating 300 gameobjects in less than a second.
Upvotes: 0
Views: 1170
Reputation: 89
When loading a map you can do it asynchronously at the start of entering the scene. This way you can put a loadingscreen during the loading time. This is a good way to do it if you are making a single player game. If it's a multiplayer game you need to sync it on the server for every other player aswell. The method for loading a scene async is SceneManager.LoadSceneAsync()
.
If you're trying to instantiate objects during runtime because you want to randomize certain objects I would recommend loading every object that doesn't need randomizing by entering the scene (so dropping them in the scene).
This is how I interpreted your question tell me if I am wrong.
Upvotes: 0
Reputation: 349
Whether you instantiate all gameobjects
in one frame or not, they will always end up in the RAM the same way. The only way to "ruin" someone's ram would be to instantiate so many gameobjects
til there is no memory left. Considering that a typical prefab
in unity is only a few kb in size and a typical RAM nowadays is a few GB in size , that would take roughly a million gameobjects.
Upvotes: 2
Reputation: 7007
Never ever make things that depends on frames, never!! There are some exceptions when this can be good but most of the time its not.
Good case: - Incremental garbage collection (still has drawbacks)
Bad case: - Your case, loading a map should be at the beginning
Why i should not make my game frame dependent?
Also 300 objects is nothing when loading a game, also from a player point of view:
What is better 10 seconds loading, or 30 seconds 15 fps then normal speed (above example is exaggerated tho)
Upvotes: 1