Hi! For my game I’m trying to make the blueprint code for when you pickup something on the ground. I have it set so that after you come into range and press a certain key, it gets the result of a sphere trace. I want to get the class of the hit actor, and then switch into different possibilities based on the other class. Currently the way I’m doing it is using a bunch of branch statements, but it looks ugly and is a bit annoying. Is there any way to do a switch statement using class?
Thanks, unfortunately that’s essentially what I’m doing (can’t use cast). Do you think I could post this over at the feature request section in the forum? Or is there a reason for this?
quick note: beware this version will return FALSE on a superclass:
if C inherits B, C instance won’t be seen as a B instance (which it is as well!) because of the name difference.
you should call an interface function on the other actor, and let the other actor perform some logic. you could have the interface function return an integer or name identifier, so you can do a switch case, but that means each new pickup actor you add, you might have to update the character as well.
its usually better to make actors know how to use interface functions, rather than knowing how to talk to many specific actors.
I try to achieve SwitchOnClass like this. Create an array that contains the classes you want to switch on and use a FindItem node to find the input class from this array and then switch on the result int. This way if you won’t change the orders of your array items it’s totally safe.
I know this post is old but I found a solution to compare which Sense is which and keeping a reference comparison at the same time. Just create a macro and do the reference comparison inside it.