"CastTo" is no substitute for "IsValid?"

Hey,

Just something I learned the hard way. I figured I’d share.

I had a problem where I’d disconnect my client from the server and the bots would fail because the player wasn’t there anymore. I was using a “CastTo” node to see if the target was good.

Apparently that node doesn’t account for much beyond casting. Things like “pending kill” (my issue) don’t get caught. When I added an IsValid before the cast, the problem went away.

Another note: the “IsValid” function (the one that returns a bool) isn’t a good substitute either because it needs the pointer to be valid in order for it to check that the pointer is valid. I’m not even sure what it’s for.

In short, the “IsValid?” node is the lord of all validity.

Cheers,
Jin

Pure functions are a liability sometimes… Plus, of course you can’t set Breakpoints on them…
For abbreviated calc work they make a lot of sense. But for logic / branching? Unconvinced!
As you discover more outlier cases like ‘is-player-still-in-game’ custom helper funcs can help.
Call from anywhere using a Blueprint Function Library that taps into your MP Game class etc…