I'm working on an Infinite Runner game. I have created many level blocks(sections) with different obstacles and pick-ups for the player. They are positioned and placed manually, in such a way, to give the player a challenge. I thought that making every block a prefab and placing every obstacle and coin as a child of that prefab is going to be easier for me..because the player is going to run and these block prefabs are going to be randomly spawned in front of him and then destroyed after the player gets past them. It worked well.

Then I wanted to make a change on my coins. So naturally I took the coin prefab, made the changes, and applied them hoping that the change is going to take effect on all my blocks... Well..it didn't. Then I found out that nested prefabs don't work in Unity, so now I have to reorganize everything again?

How do I create organized level blocks, and then make them randomly spawn in front of the player? Is there any other option besides prefabs? Don't tell me I have to use a script for every block?

Think about Banana Kong, Temple Run, Subway Surfers. The levels seem random, but it's an organized randomness with certain portions of the level repeating themselves. That's what I'm trying to do, and I don't know how to organize it...

  • 1
    \$\begingroup\$ I'm sorry. But this was not a coding question that has a single specific answer. It is about the architecture and logic of the game. How can people understand my question if I don't offer them an insight of what I'm trying to achieve first? I asked a honest question, but you didn't help a lot. Thanks anyway \$\endgroup\$ Nov 23, 2015 at 13:26
  • 1
    \$\begingroup\$ It sounds like you have the right idea for level generation, you just need a way of getting Unity to update nested prefabs. \$\endgroup\$
    – Silent137
    Jan 14, 2016 at 20:52

2 Answers 2


Please take a look at this; if I'm on the right track, I'll expand it and add narrative.

You'll draw a single terrain prefab over and over, having it morph based on the descriptions fed in via the per-instance buffer.

Example description elements:

Matrix worldMatrix;
UINT terrainTextureArrayIndex;

enter image description here

Pickups can be handled similiarly. Draw a single cube in many places with different appearance.

Example pickup description elements:

Matrix worldMatrix;
UINT pickupType = PICKUP_COIN; //Which texture(s)
UINT elapsedTime; //Used for animation
  1. Design some level blocks with combination of obstacles coins etc. (Maintain a parent child relation).

  2. Make a LevelGeneator script which will contain a Array of Transform or Gameobject.

  3. Assign the level blocks to the Script object in inspector.

  4. Randomly take a Transform and give it some force and make SetActive(true).

If its still not clear, let me know, I will provide the code


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .