Running a custom console command

So I have create a custom console command:
AZ_CONSOLEFUNC(PlayerInventoryComponent, PrintInventory, this, AZ::ConsoleFunctorFlags::DontReplicate, "Prints Inventory To Console");
and trying to figure out how to run this command in the console.

Hi @ravenboilinux,

I think it should just be this from the console


Let me know if that works!



when I run PlayerInventoryComponent.PrintInventory, I get [Warning] Unknown command: PlayerInventoryComponent.PrintInventory

Hmm okay, and is PrintInventory a member function of PlayerInventoryComponent with a parameter of const AZ::ConsoleCommandContainer& arguments?

Yes PrintInventory is a member function of PlayerInventoryComponent. It currently has the parameter const AZ::StringSet& like in the docs. I will try const AZ::ConsoleCommandContainer&. What header is AZ::ConsoleCommandContainer in?

Okay cool! Fingers crossed that works.

AZ::ConsoleCommandContainer can be found here - dev\Code\Framework\AzCore\AzCore\Console\IConsoleTypes.h - you should be able to bring it in with #include <AzCore/Console/IConsole.h> (IConsoleTypes.h gets included transitively from there).

@tom-hh in 1.27 we dont have a header file IConsoleTypes.h plus I have search the whole code base in visual studio and github for the type AZ::ConsoleCommandContainer and could not find it. I have been able to get the static version of console function to work but not the member version. I have also been able to reproduce the issue with a fresh install of lumberyard v1.27 and talked to other people in the lumberyard discord server that have the same issue.

@ravenboilinux Oooh I see… Hmm so I’ve had a quick hunt about internally to find any other example usages and the only ones I can see are referring to that particular signature. Let me ask around and get back to you, sorry for the miscommunication on my part. I’ll let you know if it’s possible or not as soon as I can.

Thank you. dont worry tom, I dont expect every lumberyard staff to know everything about the toolset that comes with lumberyard. It is a huge assortment of tools and applications that each have their own team that knows the in and out of it.

Thank you very much for your understanding @ravenboilinux :slight_smile:

I was able to find out more about the state of things and unfortunately with the current code in 1.27 I do not believe AZ_CONSOLEFUNC is fully operational. The good news is things are updated internally (apologies for sending you on a wild-goose chase for those files that are only internal at the moment). I can’t promise this will be in the next release but will keep you posted as to when it will be available.

In the meantime you might have some luck with the Immediate Window in Visual Studio. I only recently discovered you can do quite a lot of useful things there like calling functions and updating variables. If you are in Profile, disable optimizations in the file you want to call this function (add #pragma optimize("", off) at the top), and then add a breakpoint where you’d like to call the code. You then might be able to call the function you want (it’s a little temperamental I’m afraid). There’s some more info here -

It’s definitely not as slick as AZ_CONSOLEFUNC, but may be an alternative until it’s available.

Thanks for your patience and bringing this to our attention!