Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?


Product Version: UE 4.7
more ▼

asked May 24 '15 at 06:20 PM in Blueprint Scripting

avatar image

326 44 61 72

(comments are locked)
10|2000 characters needed characters left

4 answers: sort voted first

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'

alt text

To get it to work, I had to take the class name, and append _C to it in the switch case.

capture.png (61.1 kB)
more ▼

answered Dec 17 '15 at 12:14 PM

avatar image

283 15 17 31

avatar image Arty-McLabin Jan 17 '16 at 09:59 PM

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.

(comments are locked)
10|2000 characters needed characters left

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.

more ▼

answered Jan 18 '16 at 07:21 AM

avatar image

9.5k 317 202 449

avatar image MxPrime Nov 07 '18 at 08:45 PM

You are my hero! I was elbow deep in environmental queries. This is sooo much simpler

(comments are locked)
10|2000 characters needed characters left

You can create a macro like this alt text

alt text

m0.png (235.1 kB)
m1.png (99.1 kB)
more ▼

answered May 24 '15 at 06:51 PM

avatar image

3.5k 152 28 318

avatar image jfaztk May 24 '15 at 07:30 PM

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?

(comments are locked)
10|2000 characters needed characters left

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.

more ▼

answered Dec 14 '18 at 03:31 PM

avatar image


(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question