UClass::GetDefaultObject
#include "UObject/Class.h"
Access: public
Specifiers: const
Description
Returns the Class Default Object (CDO) for this UClass — the shared archetype that holds default property values for all instances. Lives on UClass, not on UObject instances.
Signature
UObject* GetDefaultObject(bool bCreateIfNeeded = true) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| bCreateIfNeeded | bool | If true (default), creates the CDO if it does not yet exist. | true |
Return Type
UObject* Caveats & Gotchas
- • GetDefaultObject() lives on UClass. Access it via MyClass->GetDefaultObject() or the type-safe helper GetDefault<T>().
- • Never mutate the CDO at runtime. It is shared across all instances and is serialized; modifying it corrupts save data and causes hard-to-debug behavior in PIE.
- • The CDO is created lazily on first request. Accessing it from multiple threads without external synchronization can cause a race condition.
Example
Read default property values C++
// Preferred — type-safe helper
const AMyCharacter* Defaults = GetDefault<AMyCharacter>();
float DefaultSpeed = Defaults->MaxWalkSpeed; See Also
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?