Hi.
I want to add variables in actor constructor.
ex) AActor1( const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
-> AActor1( const FObjectInitializer& ObjectInitializer, var_type1 var1, var_tyyp2 var2..)
How can i do that?
Hi.
I want to add variables in actor constructor.
ex) AActor1( const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
-> AActor1( const FObjectInitializer& ObjectInitializer, var_type1 var1, var_tyyp2 var2..)
How can i do that?
Subclass the Actor class, and use that in your project.
EDIT: For another option, see here: Passing arguments to constructors in UE4? - C++ - Unreal Engine Forums
Sorry! I canât understand your answer.
Please describe more detailâŠ
Sorry - I assumed a level of C++ knowledge.
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.
Hi! Thanks for your answer,
I would try to create subclass for actor and add argument, but i couldât that
UCLASS()
class AMyActor : public AActor
{
GENERATED_BODY()
AMyActor(const FObjectInitializer& ObjectInitializer, FString wname);
}
Error at AActor!!
You have to define AMyActor::AMyActor() or AMyActor::AMyActor(const FObjectInitializer& ObjectInitializer&)
For starters, the correct syntax in C++ would be
class AMyActor : public AActor
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.