# Setting up an use-key for many classes (c++)

**URL:** <https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 30, 2015, 12:20pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152 "2015-03-30T12:20:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_345bb883](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_345bb883](https://forums.unrealengine.com/u/anonymous_user_345bb883)\
**Post date:** [March 30, 2015, 12:20pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/1 "2015-03-30T12:20:55Z")

</div>

I used the action mapping on the project settings to set up a “use”-key (E), then I went to my character.cpp to make the input component : InputComponent-\>BindAction(“use”, IE\_Pressed, this, &ApracticeCharacter::usekey);  
Furthermore I declared an void usekey() function in the character.h, now I would have to implement it in the character.cpp.  
But I dont want this key to trigger one particular event like toggle a light, I just want to have other classes to be aware of this usekey() function to be called or not. I cant figure out to find the proper way to organize this. For example in the future I would like this E key with its usekey() function to pick up an item, to unlock a door, to toggle a light…and so on. So I probably dont want to cram this usekey function with all that stuff, there has to be a clean way to let other classes call this usekey() function and check if its being called or not, so the actual programming for those events remains in the classes. Please help.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3759fba9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3759fba9](https://forums.unrealengine.com/u/anonymous_user_3759fba9)\
**Post date:** [March 30, 2015, 12:55pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/2 "2015-03-30T12:55:41Z")

</div>

Hi !

I think you should consider using Interfaces :

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

This will give you the ability to use the same functions (here, useKey()) on every class that implements the Interface, and to handle the use of the E key separately.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3ecd6c40](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3ecd6c40](https://forums.unrealengine.com/u/anonymous_user_3ecd6c40)\
**Post date:** [March 30, 2015, 12:59pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/3 "2015-03-30T12:59:54Z")

</div>

Hello,

I think what you are looking for are Interfaces. That way your “use” function can easily determine if an actor is usable.  
[Here](https://wiki.unrealengine.com/Interfaces_in_C%2B%2B) is a tutorial about Interfaces.

Regards

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3ecd6c40](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3ecd6c40](https://forums.unrealengine.com/u/anonymous_user_3ecd6c40)\
**Post date:** [March 30, 2015, 1:02pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/4 "2015-03-30T13:02:02Z")

</div>

Looks like i have been a bit too slow 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3759fba9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3759fba9](https://forums.unrealengine.com/u/anonymous_user_3759fba9)\
**Post date:** [March 30, 2015, 1:06pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/5 "2015-03-30T13:06:13Z")

</div>

At least, it reinforce the fact that this should answer apfelnymous’s query 😉

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_345bb883](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_345bb883](https://forums.unrealengine.com/u/anonymous_user_345bb883)\
**Post date:** [March 30, 2015, 3:00pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/6 "2015-03-30T15:00:10Z")

</div>

Thank you, Im gonna learn about it and give a response !

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_345bb883](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_345bb883](https://forums.unrealengine.com/u/anonymous_user_345bb883)\
**Post date:** [March 30, 2015, 8:17pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/7 "2015-03-30T20:17:18Z")

</div>

Multiple class inheritance causes my compiler to mark some definitions red and state : “…is ambiguous”

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3ecd6c40](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3ecd6c40](https://forums.unrealengine.com/u/anonymous_user_3ecd6c40)\
**Post date:** [March 30, 2015, 8:21pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/8 "2015-03-30T20:21:15Z")

</div>

Do both classes you are inheriting from have a function / member with the same name?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_345bb883](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_345bb883](https://forums.unrealengine.com/u/anonymous_user_345bb883)\
**Post date:** [March 30, 2015, 8:23pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/9 "2015-03-30T20:23:49Z")

</div>

Nevermind, I did some unnecessary inheritance.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_345bb883](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_345bb883](https://forums.unrealengine.com/u/anonymous_user_345bb883)\
**Post date:** [March 30, 2015, 8:54pm UTC](https://forums.unrealengine.com/t/setting-up-an-use-key-for-many-classes-c/313152/10 "2015-03-30T20:54:13Z")

</div>

**Im having an error I cant understand.**

Info Performing 2 actions (4 in parallel)  
Info UsekeyInterface.cpp  
Error c:\program files\unreal engine\4.7\engine\source\runtime\core\public\delegates\DelegateInstancesImpl\_Variadics.inl(603) : error C2338: You cannot use UObject method delegates with raw pointers.  
Info c:\program files\unreal engine\4.7\engine\source\runtime\core\public\delegates\DelegateInstancesImpl\_Variadics.inl(749) : see reference to class template instantiation ‘TBaseUObjectMethodDelegateInstance (void),\>’ being compiled  
Info with  
Info C:\Users\Admin\Documents\Unreal Projects\practice\Source\practice\UsekeyInterface.cpp(9) : see reference to class template instantiation ‘TBaseDelegate,\>::TUObjectMethodDelegate’ being compiled  
Info ]  
Info [  
Info UserClass=AUsekeyInterface  
Info with  
Info c:\program files\unreal engine\4.7\engine\source\runtime\core\public\delegates\DelegateSignatureImpl\_Variadics.inl(72) : see reference to class template instantiation ‘TBaseUObjectMethodDelegateInstance’ being compiled  
Info ]  
Info UserClass=AUsekeyInterface  
Info [  
Info -------- End Detailed Actions Stats -----------------------------------------------------------  
Info ERROR: UBT ERROR: Failed to produce item: C:\Users\Admin\Documents\Unreal Projects\practice\Binaries\Win64\UE4Editor-practice-1676-Win64-DebugGame.dll  
Info Cumulative action seconds (8 processors): 0,00 building projects, 0,13 compiling, 0,00 creating app bundles, 0,00 generating debug info, 0,00 linking, 0,00 other  
Info UBT execution time: 6,68 seconds
