Changing component at Runtime

Hi everyone,

My use case is that my combat system (attack, animation, etc) are stored into a different componentBP for each style (1 hand, bow, boxe, etc). When my character equip a different type of weapon, i want to be able to change the component to a new one. (and keep my custom events calling the right custom events in the component)

So my character BP has a component “CombatComponentRoot”. I tried to get this component as variable, so i can change this component at runtime by one of the childBP of this root component.

Is this possible ?

thanks

Yes you can use a component variable, and add/remove components at runtime, re-assigning the variable (provided it has BlueprintReadWrite if done in BP).

Just make sure whenever you call functions on that component you use the variable and not the default component reference in blueprints.

Hi Chatouille,

Thanks for your response and yet, I cannot find the solution. The engine does not let me add a value into the variable with the type component. The screenshoot to illustrate.

Finally i use this solution. Not sure this is state of art so if anyone have better very happy to take it

Thanks

Yes you might not be able to define a default value for the variable this way.

If you have a default component to use as the default value for that variable, you can set it in construction script instead.

1 Like