Instantiating a class that inherit from AActor class throws exception

Hi all,

I have created a ActorChild class that inherit from AActor class. Then I instantiated an object of ActorChild class in another class (Testing class that inherit from AActor class) and got exception. I am fairly new to UE5 and have no clue why. Below is the screen shot of ActorChild class and testing class. If any of you understand this, please let me know. Thanks in advance

On a general note creating an instance of the same class within BeginPlay() without proper conditions can lead to infinite recursion and crash.


Regarding your issue: Instantiating a class in UE is different from standard C++ due to UE object management and garbage collection system. To instantiate an Actor class we have to use the SpawnActor function that adds it to the world:

FActorSpawnParameters SpawnParameters;
FVector Location = FVector::ZeroVector;
FRotator Rotation = FRotator::ZeroRotator;

AMyActor* MyActorInstance = GetWorld()->SpawnActor<AMyActor>(AMyActor::StaticClass(), Location, Rotation, SpawnParameters);

Keep in mind that the actor instance will stay alive in the world even after MyActorInstance goes out of scope.

Thank you. Makes a lot of sense

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.