GetAllActorsOfClass won't return Blueprint classes inheriting from C++ class

Not sure if I’m doing something wrong, but I can’t seem to get GetAllActorsOfClass to work when supplying a base C++ class that has actors implemented via Blueprints.

Example: Say I have class AMyActor in C++, and then a Blueprint that inherits from it called BP_MyActor. Then I use the following code to get all actors:

TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMyActor::StaticClass(), FoundActors);

FoundActors will come up empty. If I do the same inside Blueprints and target BP_MyActor, it works as expected. Do I need to be using some other search tool?

Turns out where I was calling this code from, GetWorld() was returning null. Getting a proper reference to the world solved my problem.