Get an actor using an ID or Name

Hi,

I am trying to update some code to work with 4.13 and some changes to the FActiveSound class have resulted in a small compilation error regarding getting an actor.
Basically, FActiveSound used to keep a reference to the audio component which I used to find the owner (i.e. actor) of that component, but now it only keeps the ID and name of the component but also the owners id and name as well. I know I could still use the audio component to get it’s owner as it has a getaudiocomponentbyid() method so GetAudioComponentByID()->GetOwner() will work, but I am wondering if there is an easier way to do this given I have the ID and name of the owner already??

But I am not sure how I can actually get the actor object using the name or id? I am hoping there is a nice easy way.

This is what I did in 4.12

AActor* SoundOwner = ActiveSound.GetAudioComponent() ? ActiveSound.GetAudioComponent()->GetOwner() : nullptr;

and since GetAudioComponent doesn’t exist anymore it errors out.

This is what I have so far, but obviously I don’t know how to get a reference to the actor object from the id (or name).

AActor* SoundOwner = ActiveSound.GetOwnerID() ? ActiveSound.GetOwnerID()//Gettheactor : nullptr;

Any help would be greatly appreciated.

So I did some digging, and it seems as of yet there is no id search or name search implemented. The solution I found was using GetActorsOfClass, and then iterating through the returned array till you find an object that matches the id/name you’re looking for.

This is what I came up with:

 TSubclassOf<AActor> ClassToFind;
 TArray<AActor*> FoundActors;
 UGameplayStatics::GetAllActorsOfClass(GetWorld(), ClassToFind, FoundActors);

AActor* Actor;
for( Actor : FoundActors )
{
    // Id comparison code
}

So it seems as if the method you’re doing right now, using GetOwner(), is probably the simpler one.

Hopefully someone else can provide you with a better solution. Good luck!