[Blueprints] How to add Actor Custom Component to Actor on runtime
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
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.
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.
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.
Okay. If no one will come with workaround - I'll have to do what you've just said. Thanks for responses!
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.
No problem, good luck!