[Blueprints] How to add Actor Custom Component to Actor on runtime

Solved

Hello guys. First I want to make it clear - it's about Actor component, not about Scene Component. So, I wonder, if there is any way to add actor custom component to actor on runtime, via blueprints scripting? Thanks in advance!

Posted Feb 9, 2016, 6:35 PM UTC

510
OptionalSteve•

So, after some event during run-time, you want to add a custom actor component to an actor blueprint?

Generally when adding a component to an actor blueprint, you use the "Add [component type] Component" node, which is also true for custom actor components. If you can see your custom component in the drop down menu when you click "Add Component" in the blueprint screen, you should be able to add your component by searching for the "Add [your components name]" node.

2
ExterminatioOP•

Thank you for your answer! Yea, I've noticed this "Add [] Component" node, but Imo it's too manually. Like, if I'm going to have >50 custom components - will be hard doing dynamic component adding, right? Cause of lacking of input node "class component" or something like this, just like in Spawn Class node.

2
OptionalSteve•

Ah yeah, I'm not sure if there's a catch all. I think it's this way because of the variability of components, but I'm not sure. You can always write an overloaded function that does what the Spawn Class node does, for the specific types of components you're creating. They'll still have to be done manually, but you'll only have to do it all once.

2
ExterminatioOP•

Okay. If no one will come with workaround - I'll have to do what you've just said. Thanks for responses!

2
Nuclear-CheeseDev•

Beware, in the documentation for AddComponent it specifically says that it is a very expensive operation when done at runtime dynamically. I have a feeling you might clobber the game thread to death with the process you just described.

Edit Currently having troubles finding where in the API it said that. I'm almost positive it was for a function that was part of the AddComponent call chain. Take my comment with a grain of salt until I find the source.

2
OptionalSteve•

No problem, good luck!

1
JoystickMonkeyAAA Dev gone Indie•

How similar are these components? Could you make one component type and then set various variables on one class of component?

2
JoystickMonkeyAAA Dev gone Indie•

If so you could dump a struct into the component when it's made and init with that, then make a data table for the struct and grab data from the table.

1
ExterminatioOP•

Hm...sounds good, but I doubt I can use it. Thanks for stopping by anyway!

1