Here’s an example. When I click “Resume Game” in my pause menu, I want to run some code in my HUD class. Do I need to put this branch with “Does Implement Interface”, or is it ok to just get HUD and call the interface function?
Specifically, I’m worried is it clean if I don’t put this condition. Do I run a risk of the game crashing or something if at some point one object doesn’t implement a certain interface and I call a function on it?
No you don’t need to ask if it implements first. This is one of the benefits of interfaces that it can be safely called on anything and will silenty fail if the object doesn’t implement the interface.
As above + small note. Lets say an interface function implementation returns a value the rest of your script relies on. Even thought the target may not have an interface, a default value will still be returned.
That’s why we ask wheter the interface exists, otherwise you might be getting gibberish (default false positive) data back.