# Making a variable that every actor has it

**URL:** <https://forums.unrealengine.com/t/making-a-variable-that-every-actor-has-it/341481>\
**Category:** UI\
**Tags:** interface, actor, unreal-engine, question\
**Created:** [December 15, 2015, 12:48am UTC](https://forums.unrealengine.com/t/making-a-variable-that-every-actor-has-it/341481 "2015-12-15T00:48:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Snowcrash5](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Snowcrash5](https://forums.unrealengine.com/u/Snowcrash5)\
**Post date:** [December 15, 2015, 12:48am UTC](https://forums.unrealengine.com/t/making-a-variable-that-every-actor-has-it/341481/1 "2015-12-15T00:48:49Z")

</div>

I am trying to have a specific set of variables that any actor can have.  
For example, when my projectile hits a wall that IsBounceable, it bounces off, and if something that IsTeleportable enters my teleporter, it teleports it.

I have already implemented this using a C++ Interface that contains a IsBouncable(), and IsTeleportable() functions that on actors that I want to make bounceable or teleportable, I just make the return parameter true. Then for example when my projectile hits a bounceable wall it sends a IsBouncable() message and if it gets back true, it bounces off, and otherwise it explodes.

Obviously I don’t think it is a really smart way to do this, because for example all non-blueprints cannot use this. If I want a static mesh to be bounceable I cannot do that without making it a blueprint and making it bounceable…

The second way I’ve thought to do this is to get my own engine build and edit AActor to have all these variables, or just make my own subclass to AActor (and then have to make all my actors that instead…). I’d rather not do this because it adds clutter, and if there is a more elegant solution, I very much prefer to do that instead.

Is there an elegant solution to my problem? Thank you 🙂

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [December 15, 2015, 1:13am UTC](https://forums.unrealengine.com/t/making-a-variable-that-every-actor-has-it/341481/2 "2015-12-15T01:13:49Z")

</div>

Then make interface in C++

> **[Interfaces](https://docs.unrealengine.com/5.1/en-US/interfaces-in-unreal-engine/)**
>
> Reference to creating and implementing interfaces.

You could also try making component

---

<div class="post-metadata">

**Author:** ![Snowcrash5](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Snowcrash5](https://forums.unrealengine.com/u/Snowcrash5)\
**Post date:** [December 15, 2015, 1:54am UTC](https://forums.unrealengine.com/t/making-a-variable-that-every-actor-has-it/341481/3 "2015-12-15T01:54:42Z")

</div>

That’s what I did, but interfaces have the problem of needing a class to inherit it in order to use it, so I cant just set any actor in the world I want to be Bounceable for example.

Components could work perfectly, but wouldn’t they be kind of heavy? (many actors having the component, needs to be found and casted to every time I want to access one of these components…?)

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [December 15, 2015, 1:58am UTC](https://forums.unrealengine.com/t/making-a-variable-that-every-actor-has-it/341481/4 "2015-12-15T01:58:25Z")

</div>

No? There interface type in blueprint i think you can cast to inteface, so i dont see how you would not ablr to use such interface in blueprint

Component should be ok, i mean it will be just to hold varables right?

---

<div class="post-metadata">

**Author:** ![Snowcrash5](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Snowcrash5](https://forums.unrealengine.com/u/Snowcrash5)\
**Post date:** [December 15, 2015, 2:12am UTC](https://forums.unrealengine.com/t/making-a-variable-that-every-actor-has-it/341481/5 "2015-12-15T02:12:56Z")

</div>

Yeah, I should do it using components.

What I meant with the interfaces is if I want to add the interface to something which is not a blueprint, like a static mesh actor in the world, I cant do that without turning it into a blueprint (Then I’d have to turn every random static mesh into its own blueprint, for example). But you can add components to pretty much anything, even if it is not a blueprint.

So components completely solve that problem and offer more flexibility. Thank you very much for the help 🙂
