Cannot call Actor Add Component inside Function Library

I made a function library and a method, the input is an Actor type variable, and when I drag off this variable, I can’t use any Add Component method.

When I do the same in normal blueprint class graph, there’s of course no problem.

Hello,

This is expected behavior. The reason that you cannot add a component inside of a function library is because the Add Component nodes store a template upon creation, and in the function library there is nowhere for this template to be stored.

Hi, thanks for the reply, could you please explain “store a template upon creation”? Thanks.

This means that when the Add Component node is created, it will store a template for whatever type of component you are adding. In the case of a function library, there is not a place for the component template to be stored, which is the reason that you are unable to use that node inside of a function library. Hope that helps.

@Sean Flint, Ok, I’d like to know more about what “a template” is, is that some kind of an object? Or maybe you can give me some hint where I should read in the engine source codes, like what files and what line numbers or function names, thanks!

A template in this context is just a basic framework for the component that you’d like to create. It’s not technically an object, as much as it is something that is stored “behind the scenes”, so to speak.

Yeah I know it’s behind the scenes, but as I read the source code, I can’t figure out the whole design, so I’d like to get some hints. At least for the source code for the good friend of AddComponent(), DestroyComponent(), it’s obviously that can be called only by the owner Actor, but I can’t see any reason why it should not be called in a function library. I can just change a few codes so that DestroyComponent() can work in function library, it can be done, but I dont know the concern of the original design.

Or, to make the question simple, will it be implemented in a future release? (I mean to be able to use Add/Destroy Component in a function library).Or, is it impossible to be implemented?

This feature is working by design, which means it will not be changed in a future release. If you’d like to make changes to the source code, you are welcome to do so.