Can we add variables/functionalities for all actors without modifying the engine actor class ?


i want to add somes functionalities / variables to all my actors.

i can make a blueprint “BP_MyActor” that inherit from AActor and add my variables and function into BP_MyActor then inherit all my futur actors from BP_MyActor :slight_smile: but… i have playercontrollers, pawns, characters that they inherit from AActor too and they wont have the functionnality and variables that i added into BP_MyActor because they inherit from AActor.

so the solution would be to open the AActor class file of the engine and add functionnality here but… if unreal engine get a new update my AActor class will be overwritten by the new version… and i dont want to edit engine class i prefere to extend them

an other solution would be to make an actor component, create function and variable inside this component and then add my component into every actor. i hate this solution too

bha i am lost at this moment, how do you deal with this problem when you want to add base functionnality / variables to all your actors ?

It sounds to me like you want to have a specific set of variables available to classes that are not necessarily in the same line of inheritance (up until AActor anyway). Without understanding what it is you are trying to achieve specifically, you could put this behavior in a component, and add these components to the actors that need them. Modifying the engine should be a last resort in my opinion.

You can use interfaces.
Provide an interface which sets and gets your variables and let your actors implement that.

For functions only, you can use Blueprint Function Libraries and parent it to the AActor class, this way every AActor can call the Function Library.

I don’t see an other solution other than modifying the source code , even multiple inheritence will not work because you can’t inheritfrom 2 UCLASS.

the best way to go is to use an ActorComponent and use a BlueprintFunctionLibrary to get/set your variables or call a func inside your actor without having to always GetComponent before

thanks for answers, actor component will be the solution then