How can I get the default values using an Object's Class in C++?

I noticed the “Get Class Defaults” node in Blueprints that gets the default values of an object using it’s class.

How can I do something like that in code?


1 Like

I’m not into coding for UE4, but from my experience with OOP a class can have public values you’d access through getters and setters (get/set). Maybe that helps you searching?

I believe I found out the way to do it.
I needed to access the Default Object associated with the the class, in my case like this:

UOAbility* Ability = Cast<UOAbility>(AbilityClass->GetDefaultObject());
EAbilityType AbilityType = Ability->AbilityType; // Default Value

Found out about this default object here: UObject Instance Creation | Unreal Engine Documentation

This only sets the variable and not the true default object. what i mean by that is that even if you set the variable once you get into editor you have to normally click reset to default for your change to appear.

I have the same question. Do you have the solution now?


In my case, it doesn’t work.

Hi, I have the similar problem.

I declare a variable with config specifier, and want to get the overridden default value from its child class without being spawned.

Some code:

UCLASS(config = MyConfig)
 class MY_API AMyBase : public AActor
     float fVarA;
 UCLASS(config = MyConfig)
 class MYGAME_API AMyChild : public AMyBase



Try to get the default value of fVarA by using its DefaultObject.

 AMyChild * MyChildDefaultObject = MyChildClass->GetDefaultObject();
 float defaultFVarA= MyChildDefaultObject ->fVarA;

However, every time I print this value, it always be 0.f. In this case, I hope it be 2.f.

How to figure out this? Any answer will be appreciated.