Why do you need to validate?
Every now and then when you are creating your game you get errors like this:
these are the result of the game trying to access something that was not properly initialized.
There are several ways to do validation of variables.
I created this example to show them out. I have this event that sets a reference to the Character movement component, this could be anything, spawned actor/widget is the perfect example where this would be used in real life scenario.
First way to validate is the “Is Valid” pure function. You get a boolean value as a result of this which you can pass into any logic you need, like this branch here.
This is useful if you have multiple conditions that need to be valid in order to perform an action. Just be careful not to use anything from the actor that is being Validated as this would result in you accessing an actor that was not validated.
Second option is the “Is Valid” macro. This approach is similar to the one above, but combines the “Is Valid” function and Branch into one node. The use of this to save you some space as it is two nodes instead of one.
The last option is the Validated Get. This node combines the “Get” variable, “Is Valid” function and the Branch. It is the most compact of them all and should be used to save up space on your blueprint graphs.
The way you get to this node is by right clicking the “Get” variable and selecting the “Convert to Validated Get” option
You can also validate get of a value from a different actor.
The disadvantage of this is that you cannot use it on return values from a function.
In general you should validate everything you can and handle the invalid state accordingly to prevent unexpected behavior in your games. There are a lot of validation already built in just type in “valid” from your object and see if it is possible to validate it.