Loading is broken when referencing components on other actors

I have two custom components.
I’ve tried to present the important parts in the code below.

class UProxyManager : public UPrimitiveComponent
{
    GENERATED_UCLASS_BODY()
public:
    uint32 RegisterProxy(UMeshInstanceProxy* Proxy);
    void UnregisterProxy(UMeshInstanceProxy* Proxy);
    
protected:
	UPROPERTY()
	TMap<uint32, UMeshInstanceProxy*> IdToProxy;
};

class UProxyInstance : public UPrimitiveComponent
{
	GENERATED_BODY()
public:	
	UPROPERTY()
	class UProxyManager* Manager;
	
	UPROPERTY()
	uint32 ProxyId;
	
public:
	void OnRegister()
	{
		Super::OnRegister();
		if (!Manager)
		{
			Manager = FindManagerForSelf(); 
			ProxyId = Manager->RegisterProxy(this);
		}
	}
	
	void OnUnregister()
	{
		Super::OnUnregister();
		if (Manager)
		{
			Manager->UnregisterProxy(this);
		}
	}
	
	UProxyManager* FindManagerForSelf()
	{
		// Implementation detail. 
		// Finds and existing or creates an appropriate actor with a UProxyManager
		// based on some other properties in this instance that are omitted for brievety
	}
};

This means that UProxyManager has a map containing pointers to components on another actor.

And UProxyInstance has a single pointer to a component on another actor.

The UProxyManager component lives on a single actor in the level that is created if necessary.

The UProxyInstance component lives on multiple actors in the level, and automatically registers with the manager actor in the scene.

All of this works great when building the level in the editor.
It starts to fall over when I save that level, and attempt to load it.
When it loads, the initial objects loaded from disk have all the correct component pointers present.
Then the Actors perform a “Reconstruction” step of their initialization, these new actors and the components that they have
no longer have valid pointers to the other actors components anymore.
The final actors/components that end up in the editor scene end up with NULL values in all the points (but the IdToProxy map has entries, just the pointers are all NULL).

Questions:

  1. Does anyone know what I’m doing wrong?
  2. Any suggestions for how to make this work?
  3. Why do actors perform this “reconstruction” step - maybe more information about that process would help me figure out where things are going wrong. The actor lifecycle documentation doesn’t seem to cover it.

Hi there!

Maybe this can help…

Thanks Kehel,
Initial attempts at using those API’s don’t seem to be solving the issue.
Do you have any insight into why this doesn’t already work? Debugging the code, the initial load is perfect, but then all actors and components are destroyed and recreated - which makes everything fall to NULL (since the original values have now been destroyed). Why does it recreate the map like this?

I’ll give the SoftObjectPtr more of a go