# referencing actor by unique name c++

**URL:** <https://forums.unrealengine.com/t/referencing-actor-by-unique-name-c/455906>\
**Category:** Editor Scripting\
**Tags:** actor, reference, beginner, unreal-engine, CPP, question\
**Created:** [September 24, 2019, 6:06pm UTC](https://forums.unrealengine.com/t/referencing-actor-by-unique-name-c/455906 "2019-09-24T18:06:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [September 24, 2019, 10:42pm UTC](https://forums.unrealengine.com/t/referencing-actor-by-unique-name-c/455906/2 "2019-09-24T22:42:58Z")

</div>

This is C++ not some magical scripting language, pointer (Type\*) is a integer containing memory address to variable which you can later access with \* or → operators. It points to actor in memory and pointer alone can’t do anything. Blueprint is no different, the blue object work same way… so you should be already used to that ;p If you confused with level blueprint, it can do that because level blueprint is part of the map and it can directly reference to actors in it, any actor can do that in property editor. But class alone don’t know what level it gonna be spawned in, so it can not reference any actor.

You need to use other functions to find actor, best practice is to store the reference right after spawn or make actor register it self to other class or reference actor in property editor (which should be you no.1 tactic if you want to link 2 actors together in level, like a switch with the light). If object is more global and has some major role in UE4 gameplay framework theres usually functions ot get it. Searching for actors is more expensive process as engine needs to loop thru all the actors in the world to find it. You got functions from blueprint for searching:

> **[UGameplayStatics::GetAllActorsOfClass](https://docs.unrealengine.com/5.1/en-US/API/Runtime/Engine/Kismet/UGameplayStatics/GetAllActorsOfClass/)**
>
> Find all Actors in the world of the specified class.

> **[UGameplayStatics::GetAllActorsWithTag](https://docs.unrealengine.com/5.1/en-US/API/Runtime/Engine/Kismet/UGameplayStatics/GetAllActorsWithTag/)**
>
> Find all Actors in the world with the specified tag.

But in C++ you can do more optimize the Blueprints allows, using iterators as you can break the iteretion loop imidietly after you find actor you looking for, saving CPU time:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

But again there lot better ways to manage references in UE4, use searching only if anything else does not work.

Theres also soft refrences which let you refrence actor by path and does not guarranty that actor will exist but it will check if and get it if needed, they also better then searching:

> **[FSoftObjectPtr](https://docs.unrealengine.com/5.1/en-US/API/Runtime/CoreUObject/UObject/FSoftObjectPtr/)**
>
> \[FSoftObjectPtr\](API\\Runtime\\CoreUObject\\UObject\\FSoftObjectPtr) is a type of weak pointer to a \[UObject\](API\\Runtime\\CoreUObject\\UObject\\UObject), that also keeps track of the path to the object on disk.

> **[TSoftObjectPtr](https://docs.unrealengine.com/5.1/en-US/API/Runtime/CoreUObject/UObject/TSoftObjectPtr/)**
>
> \[TSoftObjectPtr\](API\\Runtime\\CoreUObject\\UObject\\TSoftObjectPtr) is templatized wrapper of the generic \[FSoftObjectPtr\](API\\Runtime\\CoreUObject\\UObject\\FSoftObjectPtr), it can be used in UProperties

---

_[View the full topic](https://forums.unrealengine.com/t/referencing-actor-by-unique-name-c/455906)._
