I am trying to find a Blueprint class in my scene. I created it with Blueprints → new empty blueprint class, named it TestCam and based it on Pawn. It contains a skeletalMesh and a Camera.
I have tried using Iterators, as I usually do, but I cannot make my code find it. What class should I be looking for? I have tried APawn, AActor, UObject and even USceneComponent in this code:
USceneComponent* getActor(FString name) //i pass in the name as it is in the scene outliner
{
const TCHAR* Name = *name;
UWorld* World = GEngine->GameViewport->();
TArray<USceneComponent*> PawnActors;
for (TObjectIterator<USceneComponent> Itr; Itr; ++Itr)
{
if (Itr->GetName().Contains(name))
{
PawnActors.Add(*Itr);
}
}
return PawnActors[0];
}
First of all use TActorIterator insted of TObjectInterator, it will limit search pool to selected world.
Insted of using name, try to use UClass* of your blueprint, it will be more reliable, you can get UClass of object using GetClass() function. I don’t how you would get UClass of blueprint, one way you could do is to make C++ UClass varable somewhere that you can set in editor and compare based on that
Also keep in mind what you doing is quite expensive in performance, you could save up a lot of CPU time by making actors register themselves somewhere, list themselves in to some list in more global object like GameMode