How to do something like try/catch exception in blueprint

Can someone suggest how to do something like try/catch or exceptions in blueprints?

For example, it would be very useful to write one piece of code which would tell me if any casts in a blueprint failed instead of having to write a separate piece of the graph for each possible cast failure.

Ideally, I’m looking for something like try/catch or exceptions in C++ or python or similar languages where I can write the error handling in one place instead of duplicating the error handling in each possible place.

Thanks

Hey Xarol,

I think the easiest way to do this would be create a blueprint function (in the same blueprint or in a blueprint function library) that also accepts an input for an object type. Then inside the function process what you want to happen when a cast fails, or just get the name of the object and print it to the screen or a log etc.

You would then add this node and attach it to the Cast Failed output of a cast node, and hook up the object input to your asset reference. The try part is already being done for you by the Cast To node, so all you would need to create is the catch part.

This might be a bit limited in scope, but you could create a few different catch functions for different circumstances or object types. Not sure if that is what you are looking for, but hope it helps.

Pretty reasonable answer. Macros could also be helpful. I guess I just wish blueprints could handle exceptions but they don’t. Thanks. Marking as accepted.