Unable to save because graph is linked to private objects in an external package

I just recreated a brand new trivial project to illustrate the problem. There are two classes as follows.

UCLASS()
class TESTING_API UMyObject : public UObject
{
	GENERATED_BODY()	
};

and

UCLASS()
class TESTING_API AMyActor : public AActor
{
	GENERATED_BODY()
private:
	UPROPERTY(VisibleAnywhere)
		class UMyObject* MyObjectVar;
};
AMyActor::AMyActor()
{
	MyObjectVar = NewObject<UMyObject>(this, UMyObject::StaticClass(), TEXT("MyObjectVar"));
}

I dragged the actor class itself UMyActor (not the blueprint class of UMyActor) onto the level and attempted to save. Unfortunately, UE shows the following error.

three

Note that this problem only occurs if there is an instance of UMyActor on the level. More precisely, instances of the blueprint class of UMyActor do not cause any problem. The instance of UMyActor is the culprit as far as I know.

Question: What am I missing here?

In the chat room, DanM told me to change this to GetOuter() and it works. Thank you very much DanM. Furthermore, the code can be simplified as

MyObjectVar = NewObject<UMyObject>(GetOuter());

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.