Confirming that a UObject is valid is an important aspect of Unreal Engine development. If you attempt to manipulate or use the UObject while it's invalid, you can come across issues. And in more severe cases, engine crashes.
There are multiple methods on how to approach this —-
Method #1 - Is valid macro
The Is Valid Macro is a built-in macro that outputs the
Is Valid and
Is Not Valid execution paths. These are useful for changing the logic based on the validity of the UObject.
Method #2 - Validated get
Validated Get method is more of a hidden method that a lot of Unreal Engine developers haven't stumbled across yet. It basically combines a given variable with the above
Is Valid Macro.
Extremely useful for cleaning up blueprint layouts and should be utilized over the
Is Valid Macro whenever possible.
To convert a variable to a Validated Get —
- Right-click variable node
- At the bottom of the right-click action menu, click
Convert to Validated Get
Method #3 - Is valid getter
The Is Valid Getter function returns a Boolean that states whether the UObject is valid or not. Useful when batching together multiple different arguments.
Want to discuss this article, Unreal Engine, or media in general? Head on over to the official Unreal Directive Discord server! We're looking to foster a helpful and fun community!
If you like the content and it has helped you, please consider supporting the development of the Unreal Directive.