How to add or remove components at runtime
by Diego Santos Leao - GameBlox Studio · in Torque X 2D · 11/20/2009 (6:17 pm) · 4 replies
I have come to the conclusion that I can't add or remove components at runtime in Torque X 2D/3D. Is this really the case?
Because this would defeat part of the purpose of components, and it is very upsetting. If true, I would like to request this feature right now :)!
Because this would defeat part of the purpose of components, and it is very upsetting. If true, I would like to request this feature right now :)!
About the author
Creative director at Gameblox Interactive, a game studio focused on downloadable games and advergames. www.gameblox.net - contact@gameblox.net.
#2
I have never tried to toss one.
As Duncan has posted while I was writing, this is before registering the object.
11/20/2009 (7:47 pm)
I add components all the time:MyComp comp = new MyComp(); comp.thing = something; comp.foo = somethingelse; MyT2DObject.Components.AddComponent(comp);
I have never tried to toss one.
As Duncan has posted while I was writing, this is before registering the object.
#3
Possible usage for adding or removing components at runtime:
* using a scripting language to change the behavior of your scene object
* Maybe you want to try a component on an object that you didn't though when you ran the game.
* Maybe you are trying out new enemy behaviors as part of your prototyping process, and you want to be able to add components instead of adding all of them with enable=false at the beggining of the level - which will cause your scene to run slowly if you have many instances of that object.
Instead of asking "why" adding/removing components, we should ask "why not?".
I do believe that we can live without this functionality by putting an "Enable" property on every component and use it to mix components at runtime, but the usability of this workaround sucks anyway for prototyping.
11/20/2009 (8:17 pm)
Yeah, I want to change it after it is already on screen (that is, registered). What we do today is to enable/disable them.Possible usage for adding or removing components at runtime:
* using a scripting language to change the behavior of your scene object
* Maybe you want to try a component on an object that you didn't though when you ran the game.
* Maybe you are trying out new enemy behaviors as part of your prototyping process, and you want to be able to add components instead of adding all of them with enable=false at the beggining of the level - which will cause your scene to run slowly if you have many instances of that object.
Instead of asking "why" adding/removing components, we should ask "why not?".
I do believe that we can live without this functionality by putting an "Enable" property on every component and use it to mix components at runtime, but the usability of this workaround sucks anyway for prototyping.
#4
11/20/2009 (10:54 pm)
Without knowing the details of what you are trying to do all I can suggest is that you mod the engine, if enabling/disabling of components would suck too much. I doubt that it would be a feature that gets added as it's not typical to need to swap components in and out at runtime.
Torque Owner Duncan Colvin