Game Crash While loading Level With Many Prefabs
Okay... I'm Creating this game for mobile platforms. I'm Using Track Sections(like straight, left , sharp right etc...) to construct the track using an editor script. All the track sections are prefabs. The number of track sections goes more than 100s. It's Hard to split these track sections into different levels (because it's in development stage and i also want to test it in mobile phones). Because of this my game is experiencing crash/performance issues. Is there any other way to optimise the tracks (like generating those tracks at run time, or disabling and enabling at run time).
Note: - the track has some mesh colliders and cast shadow is set to off for the stuff that doesn't need shadows
Answer by PandawanFr · Jun 12, 2016 at 11:40 PM
I guess there are many options, but the only one I can think of right now is Serialization. What you could do is Serialize the position and all data of your tracks, and then delete them when they are too far away, and get them back later once the player is close enough to see them.
Here are a few links to get you started:
http://blogs.unity3d.com/2014/06/24/serialization-in-unity/
http://answers.unity3d.com/questions/443525/serialize-a-gameobject-including-components.html
http://answers.unity3d.com/questions/998574/save-serialize-gameobjects.html
So... I should build the track in editor, give an prefab id (like 1 = straight, 2 = left, 3 = right, 4 = split....) then create an .xml/.json file having the position,rotation and prefab id then instantiate it on runtime right?
You could just simply disable it and that wouldn't require any serialization actually. (Dunno why I didn't think of that)
But if you still wanna go with serialization, then you have to delete it, because you would just be re-generating a prefab at the same spot
Last Question... Can using a script for deter$$anonymous$$ing the position of a lot of objects result in performance impact?