Is there a way to "Switch On Class"?
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?
asked May 24 '15 at 06:20 PM in Blueprint Scripting
Not sure if you're still looking for a way to do this, but here's how I've been doing a 'Switch on Class'
To get it to work, I had to take the class name, and append _C to it in the switch case.
answered Dec 17 '15 at 12:14 PM
use interface functions:
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.
Create a function and have hit on actor with equal to class nod the branch and check that like he did on the macro, that's what I did.
answered Dec 14 '18 at 03:31 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here