Creating instances of game objects in runtime (SOLVED)

Hi

I am creating for some background animations, several game objects basically doing the same thing, containing the same sprite/animations. The only difference is when I start animating them (to give them an uneven timing).

You can check my previous post (unrelated question), where I have all those game objects in the ground collection.

Since they are 18 repetitions of the same thing, I wonder if I could create them in runtime instead of having to spend time copying/changing properties during design time.

I looked for an answer in several places, but maybe I am just missing it for lack of knowledge of the proper terms. How can I achieve that?

Thanks

Paulo

Hi @pgarcia!

I think what you are looking for are game object factories. They allow you to spawn predefined game objects at runtime. And you can set properties at the same time, for instance if you want to alter some script behavior (start offsets etc…)
A practical example is in the side scroller tutorial.

Mathias,

that is exactly what I was looking for. The side scroller tutorial helped to understand the mechanism.

Thanks!

Paul

1 Like