Hello everybody,
in my game I had severe performance issues, mainly due to poor modelling, which I did by myself as I hardly knew about how to optimize models and stuff. However, I don’t have time to redo modelling as the game is part of a university project and time is running out on me. So I separated the level into parts and now I’m ussing triggers to enable/disable parts of the level as the player approaches/leaves them. So far this works pretty good and I have gained quite some performance. But, performance seems to decrease as more parts of the level get loaded, although other parts get disabled. For example when starting the game, in the first room I have about 80 or even 90 FPS. After visiting some other areas and coming back to the starting room, I only have around 40 FPS, althought the other parts of the level have been disabled. After each call to enable/disable I am calling UnloadUnusedAssets() but I’m not sure if this is the right method to call. Are there other things I can do, any ideas?
About Resource.Load() and such stuff: I share assets between parts of the level so there is not really a way to unload them. Would it make sense to make every room a prefab (so they become assets on their own) and to use Resource.Load() and Unload() to enable/disable them?
Thank you very much for reading through my question and trying to help.
As far as I’ve noticed you should use destroy command with loaded stuff. For example in 3dsmax I can hide things, but they still affect the perfomance as they just get invisible, not removed. I guess it’s similar for you in unity here (also I’m just guessing, not my experience or knowing
).
So it would be smarter to instantiate or load the stuff when you need it and them not disable, but remove it from the game so you can be sure it doesn’t affect the performance. Use Destroy(gameObject) to remove Resources.load stuff to make sure it doesn’t cost performance.
Just suggesting, so you might want to hear other opionions ^^
Thank you very much for the swift reply. So I would have to make each of the rooms (or level parts) to a prefab and then use Instatiate() to create and Destroy() to remove the objects as the player passes the triggers. Or should I use Resources.Load() instead of Instatiate()? You mentioned it in our post but I have never used it before.
It depends on how you want to use it. With the Resources.Load() function you can load the objects from your resources ordner, destroy them to unload and don’t leech performance, or you could use Instantiate() but need to set the objects into a variable to create them. It depends on your workflow
The only thing you have to do is using Destroy() to eliminate performance leech for those objects (well as far as I understood it ^^)
You should be sure to destroy or remove those objects everytime you don’t need them. While the time I was making Wc3 maps there was something called “leaks” which means unused but still there functions… like you select a group of enemies to do something with it and move on doing other stuff… but the group is still there in the background… so everytime you call this function again to get the group of enemies you will have one more… this uses ram and performance more and more so you have to destroy that group to get performance back.