C#-Need help with C# and interacting with Console

Hello everyone,
for a while I have started to make simple games with Unity and learned basic C# with the Engine. For a couple of days I have heard that also now CryEngine is supporting C# and I thought, lets give it a try. What I want to say is I haven't that much experiences with programming (and only in C# :P), a bit knowledge about Game Development in general and I am completely new to CryEngine. So please be patient if I am not getting the most obviously things immediately.

My first title was "How I can Invoke a Method in C# from the Console".
My starting Point was:


The first parameter is the the name of the Command, okay!
but what is the second parameter "_CrySystem_cs_SWIGTYPE_p_f_p_IConsoleCmdArgs__void" ? I need something like a callback or not? Passing in a delegate or something? So I can type the command name and then the delegate gets Invoke or so?

After I can't find any solution for this problem, I have looked for a work arround.
Then I have found CVar, Console Variables. My Idea was, I can create a Variable and in the Update Method I can check if the Variable is getting a specific Value and then I call a Method.

I have implemented the following way:

Code: Select all

bool onlyOne = false; Common.ICVar myCVar; void FixedUpdate (float deltaTime) { if (!GameManagement.gameRunning) return; if (onlyOne == false) { onlyOne = true; myCVar = Engine.Console.RegisterInt("MyCVar", 0, 0); } if (myCVar == null) return; Log.ToConsole(myCVar.GetIVal().ToString()); }

For a better understanding the GameManagement class I have written by myself so I can easier create classes with OnGameStart and Update and FixedUpdate Methods (but this I working well).

"MyCVar" is registered, because when I remove the onlyOne if statement I get the error that "MyCVar" is already registered. And when I run this code its logging 0 all the time. (So far so good)
But how I can change this Variable in the Console in the Sandbox. When I write in the Console:
I get "Unknown Command"
and thats why "MyCVar = 1" or something like that also didn't work.
So how I can change this CVar in the Console?
Or is my code already wrong?
Must I use "Engine.Console.GetCVar("MyCVar");" instead of saving the ICVar in a variable in C#?

Thanks for any help!

Re: C#-Need help with C# and interacting with Console

(Sorry I am only c++ guy, but maybe I can help you find what you are looking for)
In the Native side (c++, bare with me..) the ICVar object is the actual memory location where the console value is stored (among other related data).
It does not register itself to the console.

In native land you would use one of the cvar registration helper macros such as REGISTER_CVAR or REGISTER_INT etc. Commands (callable functions) are also registered using their own macros. These use a helper object/structure provided by the ISystem common interface ConsoleRegistrationHelper. Of course, I don't think that is directly translatable to c#.

You are looking for a method to register your ICVar. Via an exposed method from some common Console Registration Helper object (ISystem), or from the IConsole common interface.

Don't forget to check out sidewynder sample c# game project on the marketplace if you havn't already.
CRYENGINE Technical Community Manager
Here to help the community and social channels grow and thrive.

My personal belongings;
Beginner Guides | My GitHub | Splash Plugin

Re: C#-Need help with C# and interacting with Console

CRYENGINE 5.3 doesn't support console commands and variables in C# yet.
But it has been implemented in 5.4 (together with a lot of new awesome features for C#) which will be released soon™.
For console commands it would be something like this:

Code: Select all

[ConsoleCommand("ResetAmmo", (uint)EVarFlags.VF_DEV_ONLY, "Resets the ammo of the player" )] static void ResetAmmo(string[] arguments) { Player.ResetAmmo(); }
I'm sorry I can't be more specific about when it will be released. If you run into anything else in C# please let me know, I'm working on making the C# experience in the CRYENGINE as good as possible.

Who is online

Users browsing this forum: No registered users and 1 guest