CreateDefaultSubObject loses its reference

Hi all,

I made some modification to one of my classes and now several things don’t seem to work with it. I have tried going back through and removing all the things i added and it didn’t fix anything. So the issue I have after stepping through the code, is that my object Abilities gets set to NULL AFTER the construction event finishes. It only does this with the Abilities object and not the other two objects that I initialize.

  AMyPlayerState::AMyPlayerState(const FObjectInitializer& ObjectInitializer) {

	//Abilities
	Abilities = ObjectInitializer.CreateDefaultSubobject<UMyAttributes>(this, TEXT("ABILITIES"));

	Abilities->SetAttributes(12, 12, 12, 12, 12, 12, true);
	OldConMod = Abilities->GetModifier(EAttributesEnum::VE_CON, true);

	//Race
	//Classes
	Barb = ObjectInitializer.CreateDefaultSubobject<UBarbarian>(this, TEXT("BARB_CLASS"));
	Bard = ObjectInitializer.CreateDefaultSubobject<UBard>(this, TEXT("BARD_CLASS"));

	UpdateClassInformation();
	Health_Current = Health_Max;

	if (GEngine)
		GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Construction Success: " + Abilities->GetFullName()));
     }

     void AMyPlayerState::BeginPlay()
     {
	Super::BeginPlay();

	if (GEngine)
		GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Begin Play: " + Abilities->GetFullName()));
     }

Somewhere between the AddOnScreenDebugMessage in the constructor and the AddOnScreendebugMessage in the begin play causes only the Abilities reference to go to NULL.

//*****Attributes*****
	UPROPERTY(BlueprintReadOnly, Category = "Atributes")
		UMyAttributes* Abilities;

	//Classes
	UBarbarian* Barb;
	UBard*		Bard;

The only code that I added which broke the whole thing where some protected ufunction server calls for giving the playerstate exp and determining if the playerstate can level.

The implementation of the playerstate is a blueprint which inherits from this playerstate class. It doesn’t have any constructor or begin play overrides.

Any help would be greatly appreciated! Thank you!

I removed the UPROPERTY from Abilities and just made a ufunction to get a reference to the object which seems to have fixed the crashing but this isn’t ideal.

If you’re using CreateDefaultSubobject, you generally want your object to be instanced. Try this:

UPROPERTY(Instanced, BlueprintReadOnly, Category = "Atributes")