UObject child class as member

Hey there,

I have a little problem with using an UObject derived class as a member in an other UObject class. It compiles fine, but my editor crashes allways after compilation, so I think there is an internal problem with that. So I tried to use a pointer to that object but that leads me to more and more problems.

So, where is the way to go?

To explain a bit more, what I want to do:
I have a class derived from UGameInstance and tried to use a custom UObject member to provide some properties in the editor in the UGameInstance class. After that I tried it with some pointers and the “NewObject” funktion in constructor of my GameInstance class. This looks good, but when I tried to compile the blueprint (yes, I created a blueprint from my GameInstance) it points to “none”.
I declared the UObject property with this macro:
UPROPERTY(EditAnywhere, Instanced, BlueprintReadWrite, Category = “State”)

This allows me to edit the properties of the UObject class. That works! But, like I currently said, after I clicked on “compile blueprint” all my settings get discarded…
Where is my mistake?

Here is my current project code:


UCLASS()
class DIEGILDEKLON_API URoundCycle : public UObject
{
	GENERATED_BODY()
	
public:
	void update(float deltaSeconds) override;

	// editor properties

	// The time at which the round starts.
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Times", meta=(DisplayName = "Round Begin", ClampMin=0, ClampMax=23))
	uint8 m_RoundBegin = 5;
	// The time at which the round ends.
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Times", meta = (DisplayName = "Round End", ClampMin = 0, ClampMax = 23))
	uint8 m_RoundEnd = 23;

	// The time at which the workers start working.
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Times", meta = (DisplayName = "Work Begin", ClampMin = 0, ClampMax = 23))
	uint8 m_WorkingBegin = 6;
	// The time at which the workers stop working.
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Times", meta = (DisplayName = "Work End", ClampMin = 0, ClampMax = 23))
	uint8 m_WorkingEnd = 18;
};

UCLASS()
class DIEGILDEKLON_API UGameLogic : public UGameInstance
{
	GENERATED_BODY()
	
public:
	void PostInitProperties() override
	{
		Super::PostInitProperties();
		Round = NewObject<URoundCycle>();
	}

	UPROPERTY(EditAnywhere, Instanced, BlueprintReadWrite, Category = "State")
	URoundCycle* Round = nullptr;
};

My understanding of the order in which constructors and settings gets applied is

MyClass()
MyClass(const FObjectInitializer& ObjectInitializer)
… Blueprint constuctors …
MyClass::PostInitProperties()

So your PostInitProperties code won’t be available when you edit the blueprint - so there’s nothing there! Try putting your code in the MyClass(const FObjectInitializer& ObjectInitializer) constructor instead.

Also, to construct a new object inside the constructor, I tend to use ObjectInitializer.CreateDefaultSubobject() like this:

CollisionStaticMeshComponent = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT(“CollisionMeshComponent0”));

Rather than NewObject.