"replacing" objects within a collection in runtime

Hello everybody!
I am trying to create a small 2d action plattformer.
I want to create different armor peaces that my character can wear. Since I split my character in 3 parts (head, torso with arms, legs) each of those bodyparts can be armored differently.
At the moment I have a “hero.collection” with the 3 different bodyparts.

So lets say the player wants to equip a new helmet which is a game object that is in the project explorer at the moment. How do I replace the head object in the player collection with the equiped helmet object in runtime?
Do I need to use a factory file? (which I thought are used to create many instances of one specific object which is not the case here)

Or is there a better way (of course there is) to implement this armor feature?

greetings from germany!
Luca

If the change is only visual and it only entails changing of the current sprite animation for head, torso and legs then you can use play_animation to change animation at runtime.

1 Like

Im using a custom animation system to be able to change the speed of an animation.
I want the armor peaces to be game objects because each armor peace should have a set of parameters like defense points, weight, etc.
So it would be great to be able to replace the current chest object with the armor object during runtime (e.g. when the player equips it)

Ok, so I guess you have at least two options:

  1. Use one armor.go and change visuals using play_animation and properties using either go.set() or via message passing.
  2. Use one go per armor type and create/delete these on the fly using factories.

I prefer option #1. Maybe someone else have another idea on how to achieve this.

okay thanks for helping me by the way. So the only way to create and delete instances of game objects during runtime is through factories?

1 Like

Yes, factories are used to create game objects or collections at run-time.

2 Likes