# How to use FAutoConsoleCommand to trigger a member function of an object instance?

**URL:** <https://forums.unrealengine.com/t/how-to-use-fautoconsolecommand-to-trigger-a-member-function-of-an-object-instance/1230848>\
**Category:** Programming & Scripting\
**Tags:** console-commands, console-command, unreal-engine, question\
**Created:** [July 16, 2023, 5:47pm UTC](https://forums.unrealengine.com/t/how-to-use-fautoconsolecommand-to-trigger-a-member-function-of-an-object-instance/1230848 "2023-07-16T17:47:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![uniwang](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@uniwang](https://forums.unrealengine.com/u/uniwang)\
**Post date:** [July 16, 2023, 5:47pm UTC](https://forums.unrealengine.com/t/how-to-use-fautoconsolecommand-to-trigger-a-member-function-of-an-object-instance/1230848/1 "2023-07-16T17:47:48Z")

</div>

Hi,  
According to the UE documentation, it is possible to use FAutoConsoleCommand to register and unregister the console command automatically.

So far I have tested that If I declare the FAutoConsoleCommand as a static member in a class, and initiate it a FConsoleCommandDelegate binded to a static member function, it works.  
But If I declare the FAutoConsoleCommand as a non-static member in a class, the compiler will throw out an error of “error C2512: ‘FAutoConsoleCommand’: no appropriate default constructor available”.  
If I declare it as a static member and initiate it a FConsoleCommandDelegate binded to a object instance member function, the compiling will fail too.

So, what is the correct way of using FAutoConsoleCommand? Is it possible to register a console command by FAutonConsoleCommand to trigger a object instance memeber function?

BTW, If I use the FConsoleManager::Get().RegisterConsoleCommand to register the console command with a FConsoleCommandDelegate binded to a member function of a object instance, it also works.

But I want to know how to manage it with the FAutoConsoleCommand.

Thanks.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/7/c/57cc70ca24d23c37609d1cb068f15947594cf158.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/7/0/5702807778dcc0fd847fa9d3b5146ca02d777dbf.png)

1\>[3/8] Compile [x64] MyObject.gen.cpp  
1\>D:\UnrealProjects\MPShooterEOS\Intermediate\Build\Win64\UnrealEditor\Inc\MPShooterEOS\UHT\MyObject.gen.cpp(75): error C2512: ‘FAutoConsoleCommand’: no appropriate default constructor available  
1\>E:\UE521\Engine\Source\Runtime\Core\Public\HAL\IConsoleManager.h(1716): note: see declaration of ‘FAutoConsoleCommand’  
1\>[4/8] Compile [x64] MyObject.cpp  
1\>D:\Unreal Projects\MPShooterEOS\Source\MPShooterEOS\Private\MyObject.cpp(10): error C2512: ‘FAutoConsoleCommand’: no appropriate default constructor available  
1\>E:\UE521\Engine\Source\Runtime\Core\Public\HAL\IConsoleManager.h(1716): note: see declaration of ‘FAutoConsoleCommand’

---

<div class="post-metadata">

**Author:** ![uniwang](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@uniwang](https://forums.unrealengine.com/u/uniwang)\
**Post date:** [July 17, 2023, 1:34pm UTC](https://forums.unrealengine.com/t/how-to-use-fautoconsolecommand-to-trigger-a-member-function-of-an-object-instance/1230848/2 "2023-07-17T13:34:52Z")

</div>

If anyone knows where to find relevant sample code, please help share it. Thank you

---

<div class="post-metadata">

**Author:** ![ztanyuki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ztanyuki](https://forums.unrealengine.com/u/ztanyuki)\
**Post date:** [August 29, 2023, 8:03am UTC](https://forums.unrealengine.com/t/how-to-use-fautoconsolecommand-to-trigger-a-member-function-of-an-object-instance/1230848/3 "2023-08-29T08:03:40Z")

</div>

well the error log speaks for itself, there is no default constructor for FAutoConsoleCommand. you need to construct the testCmd in the initializer list in UMyObject constructor

```auto
UMyObject::UMyObject() : testCmd(TEXT("testcmd::testcmd"), TEXT("test cmd"). cmdDelegate) {}

```

well that assumes that cmdDelegate is set up before the construction of UMyObject/ or in the initializer list.

But this can be every messy to read, in my case i have multiple of these commands, so I created a array of FAutoConsoleCommand and added to the array a new FAutoConsoleCommand(TEXT(“testcmd::testcmd”), TEXT(“test cmd”), cmdDelegate) during runtime so that i have time to setup cmdDelegate.

But i cant seem to bind a member function of a object instance, so i used lambdas.
