GetAllActorsOfClass causing a crash Exception access violation

I am running into this issue where I try to get all the actors of a specific class in the level (something I have done this way for many other classes in exactly the same way without issue) but instead unreal crashes, I don’t think I am doing anything weird here? Can anyone see what could be causing this crash?

EDIT:
It seems to be complaining about GetWorld() returning NULL somewhere, this doesn’t really help me further, however, since I’ve used GetWorld() in the same script multiple times earlier and it had no problems. The class derives from Actor so it should work?

I figured it out.
I forgot to add this actor to my level, which is why getWorld() returned NULL
The getWorld() I had in beginplay didnt cause a crash since beginplay is not called when the actor doesn’t exist. What i don’t understand is why calling this
pieceInteract = Cast<APieceInteraction>(UGameplayStatics::GetActorOfClass(GetWorld(), APieceInteraction::StaticClass()));
and obviously not finding an actor of that class in the world
but still being able to do this:
pieceInteract->AttachPiecesToMesh(turner[num]->turnerSpin, true, false, false);

(calling a function in that class) works without giving errors or warnings?

The pieceInteract variable should just be NULL right?

Even if there’s not an actor in the world based on that class, if the class is loaded at all, GetActorOfClass would find it’s Default Object, which is basically a base instance of everything that is loaded.

It’s important to know which APieceInteraction you are going to interact with.

1 Like