Better cast to multiple actors?

Hey guys, I have this line trace you activate with the E key. It basically serves as a general purpose interaction (open door, pickup object, push button, pull switch… etc).

It simply traces a linetrace, hits an actor, and performs a different action depending on the hit actor.

Problem is: I do have to do this infinite row of “Is that this object? No? Is that other object? No? Is that other one? No?..” and so on and so forth until you get the right actor.
Now, this is ugly and huge and I am SURE there is a better way to do that.
Does anyone know how to do this in a smarter, better way?

Thank you so much!

No you don’t :slight_smile: You need BP interfaces:

Basically, you can say to the object 'I'm interacting with you' and the object can perform some relavant action based on the event...
1 Like

Hey, thank you very much! I already knew interfaces and I used them for communication between characters and animations, but it never came to my mind they could be used this way!
Thank you a lot, this is really precious! :slight_smile:

Can you access the specific character’s variables without casting to it though?

You can add a function to the interface that returns whatever variable you are interested in, and then return that value in each implementation.

But, also, if they are all characters, then you could have a baseclass that is common to all your characters, that has the shared variables in it.

Could you provide an example? Not sure what you mean by adding a “function” to the “interface” that returns the variable. Wouldn’t you still need to cast to the certain character despite what it’s doing in its functions? Is there a node that makes a variable calllable everywhere inside of blueprints?

like say you have a bunch of different things that you want to have a Health property

you add a function to the interface called GetHealth

in each of those things you implement the GetHealth function to return whatever the Health value is

then you just Interface Call GetHealth on whatever the object is

… i am not near a pc, otherwise i’d provide a pic.

You can add a capability to the connection point that profits anything variable you are keen on, and afterward return that worth in every execution.

In any case, likewise, in the event that they are characters, you could have a baseclass that is normal to every one of your characters, that has the common factors in it.

However, might you at any point get to the particular person’s factors without projecting to it?

What if you are not able to cast to the character but want to access its variables?

Would it be possible to access the variables of a specific character without casting to it if you are able to access its variables?

Any variable you are interested in can be returned by a function in the interface, and the implementation can return the value from that function.

As well, if all your characters are characters, you could create a baseclass that holds shared variables for them all.