Download

Within Specifier and Blueprint Compiling

Hello, I have recently run into an issue when using the following code structure (declarations and defines inline for convenience, but are in seperate .h and .cpp files in my project):


UCLASS()
class MY_API UMyObject : public UObject
{
    GENERATED_BODY()
public:
    UMyObject(const FObjectInitializer& ObjectInitializer)
    {
         MyInnerUObject = CreateDefaultSubobject<UMyInnerUObject>(TEXT("SomeName"));
    }

private:
    UPROPERTY()
    UMyInnerObject* MyInnerObject;
};

UCLASS(Within=MyObject)
class MY_API UMyInnerObject : public UObject
{
    GENERATED_BODY()
public:
    UMyInnerObject (const FObjectInitializer& ObjectInitializer)
    {
         MyInnerInnerUObject = CreateDefaultSubobject<UMyInnerInnerUObject>(TEXT("SomeName"));
    }

private:
    UPROPERTY()
    UMyInnerInnerObject* MyInnerObject;
};

UCLASS(Within=MyInnerObject)
class MY_API UMyInnerInnerObject : public UObject
{
    GENERATED_BODY()
};

and finally, I put an instance of MyObject as a property in a custom UActorComponent. The problem is that when I add this custom component to a blueprint and save, it works - however, if I delete the UActorComponent that I made, and select compile, it will crash the editor. Somehow, the inner objects get their outer set to the Actor (which is marked as TRASH_ at this point). Has anyone encountered this issue? Is this a known bug?

Looks like you’re just missing the Instanced specifier on your UPROPERTY macros. You should have it for anything that you are creating as a subobject, otherwise a single instance will be shared, which is going to create problems.

My bad to not mention this, but it happens with Instanced or not as a Specifier.