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->();
for (TObjectIterator<USceneComponent> Itr; Itr; ++Itr)
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
Thanks! i actually just switched to ObjectItr to test. Will switch back.
I am trying something like:
But obviously it cant find that class. Hmmm.
… i’m not too worried about performance for this, It doesn’t run every tick, just on user interaction.
So it’s C++ class? Note that you can use StaticClass only for C++ classes, to get UClass blueprint you can use 2 methods mentioend above.
Where do you execute your getActor function?
Sorry, no it is a blueprint class. I am totally stuck here. If I have:
if (ActorItr->GetClass()), what should the rest of the code look like?
I need to somehow get a reference to the class, but that is where my mind boggles.
This function is executed on keypress currently, from inside plugin code.
In a classic case of overthinking a problem… I have been overthinking this problem. I have done this with
for (TActorIterator<AActor> ActorItr(World); ActorItr; ++ActorItr)
UE_LOG(LogTemp, Log, TEXT("GetActorLabel: %s"), *ActorItr->GetActorLabel());
UE_LOG(LogTemp, Log, TEXT("FOUND: %s"), *ActorItr->GetActorLabel());
Thanks @anonymous_user_f5a50610, yet again, for your help.