# TSoftObjectPtr points to actor within wrong UWorld when running PIE

**URL:** <https://forums.unrealengine.com/t/tsoftobjectptr-points-to-actor-within-wrong-uworld-when-running-pie/411660>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [December 7, 2017, 4:42pm UTC](https://forums.unrealengine.com/t/tsoftobjectptr-points-to-actor-within-wrong-uworld-when-running-pie/411660 "2017-12-07T16:42:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![miko1a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@miko1a](https://forums.unrealengine.com/u/miko1a)\
**Post date:** [December 7, 2017, 4:42pm UTC](https://forums.unrealengine.com/t/tsoftobjectptr-points-to-actor-within-wrong-uworld-when-running-pie/411660/1 "2017-12-07T16:42:15Z")

</div>

Hello,

I’m trying to implement registry for subset of actors within my whole game (placed in different persistent levels, different streaming levels etc.). Hence I have `TMap<FName, TSoftObjectPtr<AActor>>` to manage these actors. There as a key I use custom unique identifier and `TSoftObjectPtr<AActor>::Get()` should return valid pointer to actor if it’s presented (loaded) or nullptr otherwise.

The problem is that when I’m running PIE mode this pointer sometimes returns reference to the actor within EWorldType::Editor world instead of running EWorldType::Game or EWorldType::PIE world. When running the game in standalone mode it’s working fine, just that I need it in PIE for level designers.

So the question is whether it’s possible to implement such behavior? Force TSoftObjectPtr to return actor within specified world or something like that? Or I’m just getting it all wrong? Is that intended behavior or there’s a bug?

More details about initialization process:

1. When in editor I run custom build step to generate UDataTable that contains TSoftObjectPtr variables. To get reference value I’m doing something like that:

2. When launching the game I’m building `TMap<FName, TSoftObjectPtr<AActor>>` from the generated data table.

Thanks!

---

<div class="post-metadata">

**Author:** ![miko1a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@miko1a](https://forums.unrealengine.com/u/miko1a)\
**Post date:** [December 26, 2017, 8:47am UTC](https://forums.unrealengine.com/t/tsoftobjectptr-points-to-actor-within-wrong-uworld-when-running-pie/411660/2 "2017-12-26T08:47:17Z")

</div>

If someone faced the same problem in the PIE - in the end I’ve just avoided the issue by the cost of iterating through all actors:

```
TMap<FName, TSoftObjectPtr<AActor>> ActorsContainer; // persistent container
AActor* ResultActor = ActorsContainer[ActorID].Get(); // reference must be presented but actor can be unloaded

#if WITH_EDITOR
	// Check world type of result actor
	if (ResultActor && EWorldType::Editor == ResultActor->GetWorld()->WorldType)
	{
		// Get actual world reference (from UGameInstance for example)
		UWorld* World = ...;

		for (TActorIterator<AActor> ActorItr(World); ActorItr; ++ActorItr)
		{
			AActor* Actor = *ActorItr;

			// Check if it's the same actor (in my case it has custom component and corresponding unique ID)
			if (...)
			{
				// Fix the reference
				ResultActor = Actor;
				// Fix container content for future requests
				ActorsContainer.Add(ActorID, Actor);
				break;
			}
		}
	}
#endif // WITH_EDITOR
```

---

<div class="post-metadata">

**Author:** ![UnexpectedSquirt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnexpectedSquirt](https://forums.unrealengine.com/u/UnexpectedSquirt)\
**Post date:** [September 14, 2018, 2:34pm UTC](https://forums.unrealengine.com/t/tsoftobjectptr-points-to-actor-within-wrong-uworld-when-running-pie/411660/3 "2018-09-14T14:34:18Z")

</div>

I’m running into this problem as well, and am similarly confused as to whether this is by design or not.

My use case is checking the health state of an actor placed in a specific map from my game mode blueprint. In PIE, it returns the incorrect version of that actor resulting in wrong health values.

 ![253695-assetptr.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/2/6020455932a25f55e8a0b01cd8ad204e0a9aa604.jpeg)

It seems like there _should_ be a way to have an asset pointer return the version of that asset for the current world, but I can’t seem to find it.

Using an Actor Iterator is not a great solution, btw 😛

---

<div class="post-metadata">

**Author:** ![UnexpectedSquirt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnexpectedSquirt](https://forums.unrealengine.com/u/UnexpectedSquirt)\
**Post date:** [September 14, 2018, 9:14pm UTC](https://forums.unrealengine.com/t/tsoftobjectptr-points-to-actor-within-wrong-uworld-when-running-pie/411660/4 "2018-09-14T21:14:29Z")

</div>

After some experimentation, I have found an acceptable solution. Because Asset/Soft Pointers are pretty much just strings, you can manipulate them to take the PIE world into account.

keep in mind that I’m on 4.16.1 so you may need to adjust the language for your engine version.

```
	// Attempts to resolve the supplied Asset pointer using the calling object as a world context.  
	UFUNCTION(BlueprintPure, Category = Utilities, meta = (DeterminesOutputType = "Asset", WorldContext= "WorldContext"))
	static UObject* ResolveAsset(const TAssetPtr<UObject>& Asset, UObject* WorldContext)
	{
		UObject* Obj = ((const FAssetPtr*)&Asset)->Get();
#if WITH_EDITOR
		if (Obj && 
			WorldContext)
		{
			const FString AssetClass = Obj->GetClass()->GetName();
			const FString AssetMapName = Obj->GetWorld()->GetMapName();
			const FString CurrentMapName = WorldContext->GetWorld()->GetMapName();

			// Split using the name of the map the asset is located in, not the current map. 
			FString AssetPath, RightString;
			Asset.ToStringReference().ToString().Split(AssetMapName, &AssetPath, &RightString, ESearchCase::CaseSensitive);

			// ClassName + Path + MapPackage + CurrentMapName + AssetName
			const FString FullAssetPathString = AssetClass + "'" + AssetPath + CurrentMapName + "." + Asset.GetAssetName() + "'";

			FStringAssetReference AssetString = FStringAssetReference(FullAssetPathString);
			Obj = FAssetPtr(AssetString).Get();
 		}
#endif
		return Obj;
	}

```

 ![253733-example.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/d/8/9d853dd14f1b5bb0fbeef86431b907f341fdd167.jpeg)

Hopefully this helps anyone else with this issue!

---

<div class="post-metadata">

**Author:** ![mclark4386](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mclark4386](https://forums.unrealengine.com/u/mclark4386)\
**Post date:** [August 7, 2023, 12:10am UTC](https://forums.unrealengine.com/t/tsoftobjectptr-points-to-actor-within-wrong-uworld-when-running-pie/411660/5 "2023-08-07T00:10:22Z")

</div>

Unfortunately this doesn’t seem to work for me. Going to try to debug it and see if I can get it working. Will post back if I do^^

---

<div class="post-metadata">

**Author:** ![mclark4386](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mclark4386](https://forums.unrealengine.com/u/mclark4386)\
**Post date:** [August 21, 2023, 4:35pm UTC](https://forums.unrealengine.com/t/tsoftobjectptr-points-to-actor-within-wrong-uworld-when-running-pie/411660/6 "2023-08-21T16:35:33Z")

</div>

Sorry, we are trying to get a build out and a PIE bug is pretty low on the list of things… we are also going to move to 5.X (from 4.27.2) so at this point I’ll probably wait until after that to make sure this is still a PIE bug in there.

---

<div class="post-metadata">

**Author:** ![RitorKeir](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RitorKeir](https://forums.unrealengine.com/u/RitorKeir)\
**Post date:** [February 16, 2026, 6:32pm UTC](https://forums.unrealengine.com/t/tsoftobjectptr-points-to-actor-within-wrong-uworld-when-running-pie/411660/8 "2026-02-16T18:32:07Z")

</div>

The bug is repeated in UE 5.7.2  
Leave my solution here, maybe it will help someone

To solve the problem just use macro  
SOFTOBJECTPTR\_WORKAROUND\_PIE\_BUG() for TSoftObjectPtr member after object was loaded

`#if WITH_EDITOR`  
`#define SOFTOBJECTPTR_WORKAROUND_PIE_BUG(SoftObjectPtr) \`  
`{ \`  
` FString RemappedWorldPath; \`  
` FString SourceObjectPath; \`  
` GetWorld()->GetSoftObjectPathMapping(SourceObjectPath, RemappedWorldPath); \`  
` FSoftObjectPath ActorSoftPath{FTopLevelAssetPath{RemappedWorldPath}, SoftObjectPtr.ToSoftObjectPath().GetSubPathString()}; \`  
` SoftObjectPtr = ActorSoftPath; \`  
`}`  
`#else`  
`#define SOFTOBJECTPTR_WORKAROUND_PIE_BUG(SoftObjectPtr)`  
`#endif // WITH_EDITOR`
