Description
Global helper function that returns true if the given UObject pointer is non-null and has not been marked for garbage collection. This is the correct way to validate a UObject pointer before use.
Signature
bool IsValid(const UObject* Test) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Test | const UObject* | The object pointer to validate. | — |
Return Type
bool Caveats & Gotchas
- • IsValid() is a free function, not a member function. Call it as `IsValid(MyPtr)`, not `MyPtr->IsValid()`.
- • Do not use `MyPtr != nullptr` alone — an object can be non-null but already pending kill.
- • TWeakObjectPtr::IsValid() is a member function and handles the same checks for weak references.
Example
Safe UObject pointer access C++
UMyObject* MyObj = GetSomething();
if (IsValid(MyObj))
{
MyObj->DoWork();
} See Also
Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?