- Home /
What's the fastest way to store prefabs in an endless racing game?
I'm currently making an endless racing game, in which I use prefabs to generate new roads when the player car moves forward. I currently store the generatable prefabs in the prefabs themselves, and I don't think it's an efficient way to do it, and I've got a few ideas, how to change it:
Make a Game Object, which stores them
Access them from their folder, if there is a way to do it
The game also got different types of roads (like highway, city, B road), so I also got to check for it.
And if you've got better ideas, please share it!
Thank you! :)
I would almost make a list or dictionary, and store them and record their number as an enum. So then you could do, PrefabList[RoadType.Highway], etc. This way you don't have to remember all of the numbers associated with the various prefab types. Also, the IDE would autocomplete that for you. So you when type, "RoadType." it will bring up the list of all the available road types. I don't know if this would be the most efficient or not. And, you can pull it from the folder, if it's within the resource folder. Look up the Resource class/functions in the documentation.
I know this isn't very specific but maybe it will give you some direction.
-Dwayne Pritchett
Thanks, it seems like a good idea, I'll wait if others may answer, otherwise I'll do it in that way. And should I save the list in a separate GameObject?
I think storing it in a separate game object would be fine. A type of "Game $$anonymous$$anager" of sorts.
Answer by YoungDeveloper · Aug 11, 2015 at 03:25 PM
Create gameobject pools, idea is to maybe instantiate but almost never destroy anything. Instead set active to false unneeded gameobjects and reset active when needed. You will need to create pool manager which will hold instances of all gameobjects and their types.
Your answer
Follow this Question
Related Questions
How to instantiate random prefabs of varying size and rotation in a continuous track? 0 Answers
Prefab mode doesn't show prefab, still shows old scene. 7 Answers
Alternatives to iTweenPath for creating path for camera 2 Answers
Why is my prefab spawing underneath my player when facing left but not right? 0 Answers
Unity fire1 prefab in code 2 Answers