Download

How to use FConsoleCommandWithArgsDelegate?

Hi,

I am trying to dynamically register some console commands in my project. I created a test function in a Blueprint actor that I want to be triggered by my custom console command. Let’s call it Command_CallMeFromConsole.

Here is what I do in C++:



        IConsoleManager::Get().RegisterConsoleCommand(
            "MyConsoleCmd", // This is the name of the custom console command
            "No help for you",  // This is just help text
            FConsoleCommandWithArgsDelegate::CreateUFunction(GetOwner(), FName("Command_CallMeFromConsole")), // Here I tell it to register the function of the owner actor
            ECVF_Default
        );


Now, when I call my custom console command it works fine so far. It is triggered but this is only true for Blueprint functions without inputs (i.e. arguments).
The result I get is irritating. It looks like a Vector to me but it is also changing, sometimes it even crashes the editor. So I assume it reads some random memory and sometimes even data from illegal memory addresses.

Here is an example how one of my functions with an argument looks like:

When called via my custom console command the result I get is this:

The param1 is always changing but looks like a vector with integer values.

I also already tried to change the parameter data type to FString, FName, Object. This ended either in a crash or an empty string.

I would really appreciate if someone could point me into the right direction what I am doing wrong. Thanks!