CelloTapeGame Posted May 19 Posted May 19 When In the Unigine Engine c# is there a way to have runtime commands that change variables like floats. I am not sure how to do this in Command
arizmenda Posted May 20 Posted May 20 Hey! Could you clarify a bit what you're trying to achieve? Are you looking to register custom console commands (so you can type something like `set_speed 5.5` in the engine console at runtime)? There's a Console class with an AddCommand method in Unigine C# that lets you register your own commands. More information here: https://developer.unigine.com/en/docs/2.21/api/library/engine/class.console#adding_command If you could describe your use case in a bit more detail, it would help us give a more precise answer. Also, which version of Unigine are you using? Thanks!
CelloTapeGame Posted May 20 Author Posted May 20 (edited) Yes, that’s exactly what I want to do with it, so I can set different values for things like "set_speed 5.5" Version 2.21.0.0 Edited May 20 by CelloTapeGame
arizmenda Posted May 21 Posted May 21 Thanks for clarifying! You can use `Unigine.Console.AddCommand()` to register your own commands - the full details are in the docs. Basically: - `Unigine.Console.AddCommand("set_speed", "description", OnSetSpeed)` — register in `Init()` - Parse `argv[1]` as a float inside the callback to get the value - `Unigine.Console.RemoveCommand("set_speed")` — unregister in `Shutdown()` Spoiler float speed = 5.0f; public override bool Init() { Unigine.Console.AddCommand("set_speed", "Sets the movement speed", OnSetSpeed); return true; } private void OnSetSpeed(int argc, string[] argv) { if (argc < 2) { Log.Message("Usage: set_speed <value>\n"); return; } if (float.TryParse(argv[1], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float value)) { speed = value; Log.Message($"Speed set to {speed}\n"); } } public override bool Shutdown() { Unigine.Console.RemoveCommand("set_speed"); return true; } Also, if you'd prefer a more visual way to tweak values at runtime, check out free Toolkit add-on on our store - it includes a Runtime Editor that might be handy! 1
Recommended Posts