A constructor is what is called a âlocalâ method, meaning it belongs to the class (or subclass). If you look up a C++ tutorial, youâll learn all about it.
Once you have subclassed Actor, you can add your own behaviour (and arguments) to the constructor.
However, the easiest way to subclass something in UE4 is to go through the editor. This will add in all the necessary tags like UCLASS and make sure everything is properly added to the project. In the toolbar go to âFile > Add Code to ProjectâŠâ and select the class you want to extend from.
Unreal requires you to have the âAMyActor(const FObjectInitializer& ObjectInitializer)â constructor using ONLY the FObjectInitializer argument. When you spawn an Actor the engine does the ânew AMyActor()â call for you. Just add a method to Initialize the actor with the arguments you need rather then using the constructor for it.
Pseudo code example:
AMyActor* myActor = Spawn(AMyActor); // Spawn an actor using a class, UE4 syntax differs from my pseudocode
myActor->Init(arg1, arg2, arg3);
Then you just need to define and implement the Init method which I used above.