Why would you check if a cast is valid?

Hey,

In some of the tutorials I follow.

People kind of…religiously check if a cast is valid, Making macros to check it on repeat for a set amount of time.

So I was wondering why bother?

I know assuming is wrong, But we assume everything else will work. Why wouldn’t a cast work?

Curious
Thank ye for any insight.

ps. Tutorial I’m following atm for organising my HUD. Youtube Link (30:55 time stamp)

Hello Skyboy,

A cast wouldn’t work if the variable is null/unset.

So the IsValid checks that it is not null before trying to execute it. (If execution is tried on null variable you’ll get ‘accessed none’ errors)

I see a lot of these failed casts / accessed none when something is being called at the very beginning of ‘Begin Play’ (where some systems still need to take a few frames to gather/set references)

If something is set and will remain set It’s probably ok not to do IsValid checks, but if your logic involves clearing/changing references it’s a safety measure.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.