# Better cast to multiple actors?

**URL:** <https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401>\
**Category:** Blueprint\
**Tags:** actor, linetrace, casting, actor-blueprint, unreal-engine, question, Blueprint\
**Created:** [October 4, 2019, 7:54am UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401 "2019-10-04T07:54:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_ffdf71301](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ffdf71301](https://forums.unrealengine.com/u/anonymous_user_ffdf71301)\
**Post date:** [October 4, 2019, 7:54am UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/1 "2019-10-04T07:54:34Z")

</div>

![289148-1111.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/e/9/ae95e2af8dd2d730396ef740dca9f673227257b4.jpeg)

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!

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [October 4, 2019, 8:44am UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/2 "2019-10-04T08:44:10Z")

</div>

No you don’t 🙂 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...

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ffdf71301](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ffdf71301](https://forums.unrealengine.com/u/anonymous_user_ffdf71301)\
**Post date:** [October 4, 2019, 10:24am UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/3 "2019-10-04T10:24:03Z")

</div>

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! 🙂

---

<div class="post-metadata">

**Author:** ![bbois1999](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bbois1999](https://forums.unrealengine.com/u/bbois1999)\
**Post date:** [January 6, 2023, 10:49pm UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/4 "2023-01-06T22:49:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [January 6, 2023, 11:32pm UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/5 "2023-01-06T23:32:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bbois1999](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bbois1999](https://forums.unrealengine.com/u/bbois1999)\
**Post date:** [January 7, 2023, 5:50am UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/6 "2023-01-07T05:50:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [January 7, 2023, 6:01pm UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/7 "2023-01-07T18:01:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Red200101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Red200101](https://forums.unrealengine.com/u/Red200101)\
**Post date:** [January 8, 2023, 4:11pm UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/8 "2023-01-08T16:11:53Z")

</div>

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[,](https://essentialsclothing.co/) that has the common factors in it.

---

<div class="post-metadata">

**Author:** ![HANI630](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HANI630](https://forums.unrealengine.com/u/HANI630)\
**Post date:** [January 20, 2023, 11:56am UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/9 "2023-01-20T11:56:25Z")

</div>

However[,](https://essentialsclothing.co/) might you at any point get to the particular person’s factors without projecting to it?

---

<div class="post-metadata">

**Author:** ![nice561274](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nice561274](https://forums.unrealengine.com/u/nice561274)\
**Post date:** [January 22, 2023, 3:51pm UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/10 "2023-01-22T15:51:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Essentials\_Cloth](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Essentials\_Cloth](https://forums.unrealengine.com/u/Essentials_Cloth)\
**Post date:** [January 29, 2023, 3:57pm UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/11 "2023-01-29T15:57:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iqra50](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@iqra50](https://forums.unrealengine.com/u/iqra50)\
**Post date:** [June 6, 2023, 11:37am UTC](https://forums.unrealengine.com/t/better-cast-to-multiple-actors/456401/12 "2023-06-06T11:37:05Z")

</div>

Any variable you are interested in can be returned by a function in the interface[,](https://essentialsclothing.co/) 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.
