- Home /
game glitches on play
hey guys got a small problem.
I have a level in my game that is quite big, so naturally there are lots of objects in it. Now the problem is, when i start the game it lags for about 5 seconds then runs fine after my graphics card kicks in. I know this is a problem with too many animated objects in my scene. So my question is
Is there a way i can hibernate all the game objects/ NPC's and enemies included, until the character comes into visual range. For instance there a 3 towns in this scene each have NPC's that walk around and interact... any help would be great, I only know C# if it is a scripting issue, i thought about instantiating the GO's but i think if my player walks away then returns they will instantiate again ontop of the others thus creating more issues... thanks in advance.
You can hibernate the objects(youll need to write some code ;) ), and that most likely will solve some lag issues but it may not completely. It may be a combo of lots of code being run in Start() and Awake() and lots of objects initializing. There are alternatives to this, which is running the code when it needs to get fired and setting variables at that time, dynamically adding/removing of objects in the scene, adding heavier components dynamically(rigidbody for example).
Its really tough to say, but there is no easy button for this type of problem. You might want to re-think some of the structure, lean up the code, aim for a more event based loading system. One thought is to make each town have a dedicated trigger, once the player enters that trigger you can call a "WakeUp" type function on all of the people(or Instantiate groups based on multiple triggers or events).