Easy chunk prefab creation
In my infinity runner game, level is generated randomly , but after a while I decided to use predefined prefabs of parts of the level and place it randomly to make level more organised. However I still want to spawn each object in this level prefab from the script, not the entire prefab with all the models. The reason of this is because I want to use object pooling, as well as to add some variations to the objects in the level prefab when they spawn (randomly rotate,scale,etc).
I see one possible solution :
in the editor we somehow create an array of objects we want to spawn , with position and rotation values.
In game, when we instantiate new world area(chunk), we use this data and instantiate each object in the array from script.
However I don't know how to setup this prefab/array of objects with all the info, in a somewhat user friendly way , maybe it's possible to make a regular prefab with all the stuff , then some script saves all values into array (in editor, not in game) , or maybe there is much better way to do that ?
You can save data in a ScriptableObject and with a script create and positionate GameObjects based on the saved data, see Introduction to Scriptable Objects
Ok . i learned a little bit about scriptable objects, that's a good information to know , gonna use Scriptable objects for level generation settings, and chunk data saving, However I still need information regarding how to easily save all the data into the Scriptable object .
Right now I think about using special script , with custom button in the inspector , pressing this button will get all the children in the chunk (all chunk objects are children of chunk root Game Object), and write data to the Scriptable Object generated for that particular chunk.
Don;t know if there are better solutions , but that's what came up to my $$anonymous$$d :)
Your answer
Follow this Question
Related Questions
How to instantiate bunch of cubes randomly in particular direction? 0 Answers
How do I generate a grid of random shapes that tile perfectly? 0 Answers
Help with simple generation problem 0 Answers
Generate Random Numbers a Distance Apart From Each Other 1 Answer
Randomly generate blocks on a flat map 0 Answers