Hey, man just wanted to let you know that I think your tutorials are by far the best I have ever seen. Better then Brackeys, better than anything else. They are not only well made but you also pick relevant topics and topics most other tutorial channels don't cover. I also feel like you are actively working in the industry yourself. The best however is the general presentation, not only visually, but your approach to teaching something is so much better than those step by step tutorials that flood RUclips. You tell us the general idea and roughly show the steps, in how you achieved something. That's great for beginners because they have to do the critical work themselves and learn faster that way, on the other hand, its also great for more advanced game devs because they can just get an idea of the systems you explain and don't have to go through all the steps they already know. Although I would consider myself an experienced developer I learnt something new from nearly every video you made. Well done and best of luck! Markus (Phodex Games)
For anyone stuck the OnToggleDebug method works by using the new input systems send message feature, you need a player input component on whatever game object has the debugcontroller script on it. Once you have that any function that is the name of one of your input actions with the prefix "On" will be triggered when you press that key.
@@vantinhnong2206 i didn't get to implement any version I find, i measure the tutorial by how complicated the code is and how good does the tutorial guy explain it
@@vantinhnong2206 actually he intentionally don't share the script files. The TLDR of why is that he want to encourage us, viewers, to explore the code by ourselves, looking what he did, understanding it and making our own version
Kudos for a great tutorial. Find it a bit annoying to have to mouse-click in the input field, before you can start typing? Simple -- before drawing the text field, use the GUI.SetNextControlName("name"); then simply use that name with GUI.FocusControl("name"); Your cursor will automatically be in the field. GUI.SetNextControlName("console"); input = GUI.TextField(new Rect(10f, y + 5f, Screen.width - 20f,20f), input); GUI.FocusControl("console");
I really enjoy how you do not read out loud what code you write but rather focus on giving us some more information and stuff, while still showing the whole code so that even us beginners can follow along.
Big fan of these videos! Incredibly impressed by how you manage to make tutorials about things everyone really needs in their games but hardly anyone ever talks about. Just wanted to say that you inspired me to make tutorials of my own and while they're nowhere near the same quality, making them these past few months has really helped in these troubling times.
I just created a debug console a few days ago, didn't add input command yet. This video will come in handy, it looks super polished so far. It's great timing. Thank you!
I was confused about 'Action' type you put in at 4:04. I figured it out by pausing at the right time and noticing it says 'System' on the side. If anyone else is stuck there, all you have to do is type 'using System;' at the very top which will allow you to use the 'Action' type. It might be best if you specifically point out that you have to do something like that in your future videos.
If it weren't thanks to people like you, many of us would be stuck in tutorials like this. Thanks for adding what the tutorial guy thought wasn't relevant.
Ok, so I would have done it differently. Mainly, instead of making it an object, make it an attribute. Then when the game starts it looks through every assembly (and if it supports modding, the assemblies it loads) and looks for that attribute. The attribute only requires 1 or 2 parameters; It could require a description but the attribute finder uses the method name as the command, or it can require a command name and description. And to expand upon it, it looks at the parameter's of the method using reflection. I would only restrict it to primitives and strings only. This way is much better imo because you do not have to instantiate anything for the commands; It is done for you automatically.
100% agree. It's similar to MenuCommand and other attributes used by Unity. With some extra work, you could even add documentation to it. Furthermore, you could make it so some methods can have a parameter that takes a list of characters: for console-like command options.
Cool tutorial, I will definitely be implementing something like this into my current project. My main critique is that if you are going to make use of things like interpolated strings and action delegates, I would at least mention them by name so that people have the ability to search the terms and learn about them independently.
Ideed, coz I've never seen this style of coding before, and I don't understand it. I can get the logic, mainly because of his explanation, but I still don't understand it.
I don't get it, he should mention about a thing the person don't know to that person go search about it? I think that's too much :P The point of the video is not explain Action or anything else he uses to build the Debug Cheat Console Like Tiago I didn't know what was Action and searched independently Try here, Tiago: docs.microsoft.com/pt-br/dotnet/api/system.action-1?view=netcore-3.1
@@dnz8792 How exactly does me saying that he should call them by their correct terms so people can do independent research lead to you making the assumption that I said he should explain how they work?
@Steven Docker I totally agree with you, i'm pretty new in the stuff, i understand many things like the new input system, but in this video are missing some parts. its frustrating to me becouse of 2 things, i did not understand how did he trigger the button without listener in the script and the part with private Action command, i understand now the input thing but the Action remembered me of a delegate . And now i'm confused why i need this and where the hell it is implemented.
Great tutorial, very well explained. Minor point: Contains() is a poor choice for comparing their input to the list of commands since it will rapidly get confused by commands that share substrings. What you really want to do is to get the left part of the input (delineated by a space or the end of input) and compare that to the command list.
Thanks for the amazing video. Here is an OnGUI() function with variables instead of magic numbers, if anyone is interested: (Notice, I feel like there are some errors in the naming. Though my brain is about to melt, so I'm not sure what's supposed to be what. Perhaps you may just leave them as they are, since they aren't too important.) void OnGUI() { if(!showConsole) return; float y = 0; float historyLength = 200; float lineHeight = 20; float inputFieldHeight = 10; float verticalSpacing = 30; float padding = 5; if(showHelp) { GUI.Box(new Rect(0, y, Screen.width, historyLength), ""); Rect viewport = new Rect(0, 0, Screen.width - verticalSpacing, lineHeight * commandList.Count); scroll = GUI.BeginScrollView(new Rect(0, y + padding, Screen.width, historyLength - inputFieldHeight), scroll, viewport); for (int i = 0; i < commandList.Count; i++) { ConsoleCommandBase command = commandList[i] as ConsoleCommandBase; string label = $"{command.Format} - {command.Description}"; Rect labelRect = new Rect(padding, lineHeight*i, viewport.width - historyLength, lineHeight); GUI.Label(labelRect, label); } GUI.EndScrollView(); y += historyLength; } GUI.Box(new Rect(0, y, Screen.width, verticalSpacing), ""); input = GUI.TextField(new Rect(inputFieldHeight, y + padding, Screen.width - lineHeight, lineHeight), input); }
This man here deserves more views and subs! This is one of the few game dev channels that provide clean and very practical tips and tutorials. Keep up the good work man!
Super useful its gotten to the point where I've just made just one script that i can copy and paste into any project and rapidly setup with an input and output text and begun running commands at runtime. Consoles are a great necessity for devs, :3 Course i grew up with Unreal, Unreal Tournament, Harry Potter and the Philosophers Stone and other Unreal 1 Engine games. So command consoles were just fun tools back then but really do save devs loads of hassle even now. Not sure why dev keep steering clear from making them these days, :O
One of the best Unity channels on RUclips. Congratulations on the great and hard-to-find content out there based on your game development. The only negative point (but completely understood) is the frequency of the videos. It would be great to have a course at Udemy with only Unity tips and updated by month (for example), it would be an insta-buy.
your videos have by far the highest value on RUclips. However, they are a little bit fast to be honest; I think a bit more explanation would be much appreciated. Or, if you want these videos to stay this short, I suggest you making a complete series on making a full project while using all these professional skills (not the basic stuff which we can find everywhere on RUclips), step by step, and no need to edit and make all these fancy animations and comments, just a simple stream-like video tutorials, which will require zero editing, and I promise many people will enjoy them as well. I am not saying that all the fancy stuff are useless, they are in fact so amazing and attractive. Anyway, wish you the best of luck, and thank you so much.
there are a few people that make videos in this format (like Derek Banas) for programmers that just want condensed information. They don't waste literally any time, and the intention is that if something was too fast, you rewind the video. At first this format bothered me for the same reasons it does you; the videos are too fast. After years of dealing with slow, 20 minute videos that explain concepts that could be understood in a tenth that time however, I've come to really appreciate these kinds of videos.
You could also add an attribute for that if you just want to call a function directly, place an Attribute above it with the command name and the description and you're done with that function.
I copied EVERY line of that code. It does not work with the new input system Best I could do is patch it with the old input system by listening in for a "\" key (to open/close the console) and the return key to check the input, but then only if the input field is not selected. What am I missing? Before you suggest it, it's been 3h of me watching every possible tutorial on the new input system and they all have a different method, both between each other and from what it's in this video By this of course I don't mean to put down the work you've done, it's a very well thought and cool tutorial, which is one of the reasons I subscribed to your channel. In my opinion it's missing a likely trivial but critical passage that I can't seem to find
@@LeoninMinecraft Actually yes. I'm going to copy down the process and code I use right below. • Create a folder in "Assets", I usually call it "Input" or some such • in there I go right-click -> create -> InputActions. I do not generate a c# class for it • I pin the Input Actions menu near the scene/game tabs and fill it with the maps/actions/bindings I want. Remember to save it • on the game object I want listening to commands I add the Player Input component, then drag&drop the InputAction asset created before in the first slot, choose the actionmap I want the game object to be obeying, and as for behaviour choose "Invoke unity events". The rest I leave as is. This is all the "prep work" I go through, the rest is done by code using UnityEngine.InputSystem; public class DebugController : MonoBehaviour { private InputActionMap actionMap; private void Awake() { actionMap = GetComponent().actions.FindActionMap("Debug"); // "Debug" is the actionmap name actionMap.actions[0].performed += OnToggleConsole; // I only activate the toggle console trigger at first // it's not optimal, but I grab the actions from the actions array in the actionmap. VERY dependent on the order BuildCommandList(); //builds the list of commands for debugging - not a part of the input system/actions/etc circus } public void OnToggleConsole(InputAction.CallbackContext ctx) { if (showConsole) { actionMap.actions[1].performed -= OnCommandConfirmed; //IF I want to close the console, I deactivate the trigger to confirm commands showConsole = false; return; } else { actionMap.actions[1].performed += OnCommandConfirmed; //IF i want to open the console, I activate the trigger to confirm commands showConsole = true; return; } } } This is the code I arrived to after much cursing and sweat, and it seems to work for me. If you still have problems, do tell and we'll find some solution I hope. P.S. Technically you should also unsubscribe to actionMap.actions[0].performed when the object you are using is to be destroyed. This way you don't run the risk of triggering some left over code from the trash and crashing the program
@@telli5868 OnCommandConfirmed is a function that is called whenever actionMap.actions[1] is triggered. As this is for a cheat code inserter, I mapped actions[1] to the "enter" key being pressed, as you would at the end of a command input, so that's when the OnCommandConfirmed method is called. The function itself is merely a string parser to recognise the command on input and looks kinda like this (I don't have the code, new pc): public void OnCommandConfirmed(InputAction.CallbackContext ctx) { if( input == commands[1]) Commands[1](); else if (....) .... } Hopefully it's clear enough?
I'm getting an error around 3:15 saying "Assets\Scripts\DebugController.cs(23,5): error CS0103: The name 'input' does not exist in the current context" (also at (23, 74)) any suggestions on fixing this?
Thanks. I hope you continue to make more videos!! Would love to see one for an target box in games like MMO's or RPG's that highlight the enemy with various options or ways to do so. That would be great :)
Wonderful job, but i just wanted to say that i have adapted the scripts to work with the old input system. This new input system needs updated tutorials, on how to integrate and even replace previous code.
Oh nevermind, I found a comment by Mohammed Omar ruclips.net/channel/UCfSzQ3JjiwmuL0SWMH1uA7Q about how to do it. From them: "An easy fix for this is to add these lines at the end of the OnGUI function and remove them from the update if (Event.current.type == EventType.KeyDown && Event.current.character == ' ') { HandleInput(); input = ""; } "
I agree with everything you said about testing during development. I have said this years ago that the reason for codes and console cmds is to test the functionality of the game. Who in their right mind would play the game to level 99 just to test it.. let's skip.to that level and test it
Personal preference around readability. Habits formed after working on teams with shared code over the years. Making a private variable, and a public getter is much clearer and faster to parse on large projects in my experience.
It would have been great if you had explained how you did the actions or at least what parts of the code you should skip if you want to activate it another way.
Worth knowing: It's the ` (grave accent) for UKers, but that key is ~(tilde) for Americans, and every now and then a game will code it poorly and so trying to type an apostrophe will open console.
Nice idea. I had a similar one, where i am able to mark a method with an attribute [ConsoleMethod("name", int additionalParameters, etc...)]. With reflection i just managed them in a list, like you did. That way, i dont have to manage the list manually, but of course i do have more computional cost at the beginning.
I actually used something like this for commands of a cli app. It'll be real flexible but yea, reflection with take quite a bit of performance for loading, tho i think it's worth it.
Hey, I know this is a very old comment but I'm trying to implement this as well but I've never used reflection before. I made the attribute and got all the methods with that attribute, I just don't know how to create DebugCommands from those methods, like how to create the generic objects and use the already existing implementation of the method in the action
This isn't an issue at all. That's because I assume that you are using the old input system where the input not associated with global events like the new input system An easy fix for this is to add these lines at the end of the OnGUI function and remove them from the update if (Event.current.type == EventType.KeyDown && Event.current.character == ' ') { HandleInput(); input = ""; }
Well, whenever you type a new character in the input (check the length of the input string) search your list of commands if they contain the entered letters (command.Contains(input)) and then just display the list of fitting commands on-screen. Then if you click on an entry from that list just execute the regarding command. You can of course advance this with more functionality if you want, but that should work pretty well as foundation.
How can we activate directly text writing before clicking to panel? If i open the panel, to write, i need to click it. Is there anyway to make it writeable as soon as we open?
every time i try to fix an error, another one pops up. i dont have the input system in my version, (or at least i dont think) and if i try to switch my project version to a newer version, everything gets corrupted. please help!
Am I the only one where who gets errors because of the Action Object? Is Action a class he created in another tutorial? I have an error because of Action, the type or namespace name "Action" can´t be found
Crap, I know this is kinda unrelated but I just have to share my pain... I was going to a unity project I had in the windows file explorer and pressed CTRL + D for duplicate. Turns out it deletes the folder instead... and I have automatically clean Recycle bin on.
Hi there, thanks for this amazing video. I have the system working, however when I press the backquote key to open the console window, the command I type gets a backquote symbol (`) in front of it. How can I prevent this? Thanks! :)
hey there can you please help me to make small command for me? what i want is i press key command panel opens and i type then hit enter then should return string what i typed in command that's it if you interested to help ill provide you plugins
Just a quick question, I know how to use the inputSystem with the "CallbackContext" but, how do we use the "InputValue"? I never see where we could use it....
InputSystem supports different types of joysticks and gamepads. So sometimes you may need a particular value of for example an x axis of the left stick of PS4 controller when callback happens. That's the situation when the InputValue makes sense
here is add. If you write set_gold / with space after command it will be parce exeption. Also if you do not check count and write just set_gold. If you need here is solution private void CheckCommand() { if (_showConsole) { string[] properties = _input.Split(' '); for (int i = 0; i < commandList.Count; i++) { DebugCommandBase commandBase = commandList[i] as DebugCommandBase; if (_input != null && _input.Contains(commandBase.comandId)) { if(commandList[i] as DebugCommand != null) { (commandList[i] as DebugCommand).Invoke(); } else if (_input != null && commandList[i] as DebugCommand != null && properties.Length > 1) { if (int.TryParse(properties[1], out int value)) { (commandList[i] as DebugCommand).Invoke(value); } } } }
Hey, man just wanted to let you know that I think your tutorials are by far the best I have ever seen. Better then Brackeys, better than anything else. They are not only well made but you also pick relevant topics and topics most other tutorial channels don't cover. I also feel like you are actively working in the industry yourself. The best however is the general presentation, not only visually, but your approach to teaching something is so much better than those step by step tutorials that flood RUclips. You tell us the general idea and roughly show the steps, in how you achieved something. That's great for beginners because they have to do the critical work themselves and learn faster that way, on the other hand, its also great for more advanced game devs because they can just get an idea of the systems you explain and don't have to go through all the steps they already know. Although I would consider myself an experienced developer I learnt something new from nearly every video you made. Well done and best of luck!
Markus (Phodex Games)
brakeys is better
@@jgoglescu You can think that way if you want.
@@PhodexGames bEtTeR tHaN bRaCkeYs. Like who the fk are u niqqa
@@uxdecipher1724 Definetly not a niqqa lol.
For anyone stuck the OnToggleDebug method works by using the new input systems send message feature, you need a player input component on whatever game object has the debugcontroller script on it. Once you have that any function that is the name of one of your input actions with the prefix "On" will be triggered when you press that key.
I've struggled a lot to find a good tutorial on cheat console and this is the simpler and best tutorial on it!
Can you share your project? If it just a recreation of course.
@@vantinhnong2206 i didn't get to implement any version I find, i measure the tutorial by how complicated the code is and how good does the tutorial guy explain it
@@Pedro_Marangon These tutorials are so great but its creator forgot to put it on Github, really sad!
@@vantinhnong2206 actually he intentionally don't share the script files. The TLDR of why is that he want to encourage us, viewers, to explore the code by ourselves, looking what he did, understanding it and making our own version
@@Pedro_Marangon so I won't be able to figure out what to change so this works with the basic input system than great
Kudos for a great tutorial.
Find it a bit annoying to have to mouse-click in the input field, before you can start typing?
Simple -- before drawing the text field, use the GUI.SetNextControlName("name"); then simply use that name with GUI.FocusControl("name");
Your cursor will automatically be in the field.
GUI.SetNextControlName("console");
input = GUI.TextField(new Rect(10f, y + 5f, Screen.width - 20f,20f), input);
GUI.FocusControl("console");
I really enjoy how you do not read out loud what code you write but rather focus on giving us some more information and stuff, while still showing the whole code so that even us beginners can follow along.
Big fan of these videos! Incredibly impressed by how you manage to make tutorials about things everyone really needs in their games but hardly anyone ever talks about. Just wanted to say that you inspired me to make tutorials of my own and while they're nowhere near the same quality, making them these past few months has really helped in these troubling times.
Could this be the single most important tutorial ever made? Leaning strongly towards 'yes' here. Thank you, Game Dev Guide Guy!
Nice video but mother of god the whitespacing at 5:47 I'll never forget
ahahaha I totally agree! :P
I just created a debug console a few days ago, didn't add input command yet. This video will come in handy, it looks super polished so far. It's great timing. Thank you!
I was confused about 'Action' type you put in at 4:04. I figured it out by pausing at the right time and noticing it says 'System' on the side. If anyone else is stuck there, all you have to do is type 'using System;' at the very top which will allow you to use the 'Action' type. It might be best if you specifically point out that you have to do something like that in your future videos.
Thanks you really help me!❤
I was stuck here, thanks man!
thanks
If it weren't thanks to people like you, many of us would be stuck in tutorials like this. Thanks for adding what the tutorial guy thought wasn't relevant.
Ok, so I would have done it differently. Mainly, instead of making it an object, make it an attribute. Then when the game starts it looks through every assembly (and if it supports modding, the assemblies it loads) and looks for that attribute. The attribute only requires 1 or 2 parameters; It could require a description but the attribute finder uses the method name as the command, or it can require a command name and description. And to expand upon it, it looks at the parameter's of the method using reflection. I would only restrict it to primitives and strings only. This way is much better imo because you do not have to instantiate anything for the commands; It is done for you automatically.
100% agree. It's similar to MenuCommand and other attributes used by Unity.
With some extra work, you could even add documentation to it. Furthermore, you could make it so some methods can have a parameter that takes a list of characters: for console-like command options.
Oh yeah, if someone does this, please add tab auto-completion.
That's a really nice idea, you should really make a tutorial :)
Cool tutorial, I will definitely be implementing something like this into my current project.
My main critique is that if you are going to make use of things like interpolated strings and action delegates, I would at least mention them by name so that people have the ability to search the terms and learn about them independently.
Ideed, coz I've never seen this style of coding before, and I don't understand it. I can get the logic, mainly because of his explanation, but I still don't understand it.
I don't get it, he should mention about a thing the person don't know to that person go search about it?
I think that's too much :P
The point of the video is not explain Action or anything else he uses to build the Debug Cheat Console
Like Tiago I didn't know what was Action and searched independently
Try here, Tiago:
docs.microsoft.com/pt-br/dotnet/api/system.action-1?view=netcore-3.1
@@dnz8792 How exactly does me saying that he should call them by their correct terms so people can do independent research lead to you making the assumption that I said he should explain how they work?
@Steven Docker
I totally agree with you, i'm pretty new in the stuff, i understand many things like the new input system, but in this video are missing some parts. its frustrating to me becouse of 2 things, i did not understand how did he trigger the button without listener in the script and the part with private Action command, i understand now the input thing but the Action remembered me of a delegate . And now i'm confused why i need this and where the hell it is implemented.
Nice work! I love your tutorials! Will deffo be adding this into my game :D
i've just been hiding all my debug behind intentionally awkward key combos so this looks a lot smoother, i'll try it out thanks
Great tutorial, very well explained. Minor point: Contains() is a poor choice for comparing their input to the list of commands since it will rapidly get confused by commands that share substrings. What you really want to do is to get the left part of the input (delineated by a space or the end of input) and compare that to the command list.
Thanks for the amazing video. Here is an OnGUI() function with variables instead of magic numbers, if anyone is interested:
(Notice, I feel like there are some errors in the naming. Though my brain is about to melt, so I'm not sure what's supposed to be what. Perhaps you may just leave them as they are, since they aren't too important.)
void OnGUI()
{
if(!showConsole) return;
float y = 0;
float historyLength = 200;
float lineHeight = 20;
float inputFieldHeight = 10;
float verticalSpacing = 30;
float padding = 5;
if(showHelp)
{
GUI.Box(new Rect(0, y, Screen.width, historyLength), "");
Rect viewport = new Rect(0, 0, Screen.width - verticalSpacing, lineHeight * commandList.Count);
scroll = GUI.BeginScrollView(new Rect(0, y + padding, Screen.width, historyLength - inputFieldHeight), scroll, viewport);
for (int i = 0; i < commandList.Count; i++)
{
ConsoleCommandBase command = commandList[i] as ConsoleCommandBase;
string label = $"{command.Format} - {command.Description}";
Rect labelRect = new Rect(padding, lineHeight*i, viewport.width - historyLength, lineHeight);
GUI.Label(labelRect, label);
}
GUI.EndScrollView();
y += historyLength;
}
GUI.Box(new Rect(0, y, Screen.width, verticalSpacing), "");
input = GUI.TextField(new Rect(inputFieldHeight, y + padding, Screen.width - lineHeight, lineHeight), input);
}
This man here deserves more views and subs! This is one of the few game dev channels that provide clean and very practical tips and tutorials. Keep up the good work man!
Super useful its gotten to the point where I've just made just one script that i can copy and paste into any project and rapidly setup with an input and output text and begun running commands at runtime. Consoles are a great necessity for devs, :3
Course i grew up with Unreal, Unreal Tournament, Harry Potter and the Philosophers Stone and other Unreal 1 Engine games. So command consoles were just fun tools back then but really do save devs loads of hassle even now. Not sure why dev keep steering clear from making them these days, :O
One of the best Unity channels on RUclips. Congratulations on the great and hard-to-find content out there based on your game development.
The only negative point (but completely understood) is the frequency of the videos.
It would be great to have a course at Udemy with only Unity tips and updated by month (for example), it would be an insta-buy.
your videos have by far the highest value on RUclips. However, they are a little bit fast to be honest; I think a bit more explanation would be much appreciated. Or, if you want these videos to stay this short, I suggest you making a complete series on making a full project while using all these professional skills (not the basic stuff which we can find everywhere on RUclips), step by step, and no need to edit and make all these fancy animations and comments, just a simple stream-like video tutorials, which will require zero editing, and I promise many people will enjoy them as well. I am not saying that all the fancy stuff are useless, they are in fact so amazing and attractive. Anyway, wish you the best of luck, and thank you so much.
there are a few people that make videos in this format (like Derek Banas) for programmers that just want condensed information. They don't waste literally any time, and the intention is that if something was too fast, you rewind the video. At first this format bothered me for the same reasons it does you; the videos are too fast. After years of dealing with slow, 20 minute videos that explain concepts that could be understood in a tenth that time however, I've come to really appreciate these kinds of videos.
This channel deserves 1M subs. Thumps up!
is this the #1 tutorial speedrunner?
This vid is pure gold!!!
Thankyou so much for sharing!
You could also add an attribute for that if you just want to call a function directly, place an Attribute above it with the command name and the description and you're done with that function.
I copied EVERY line of that code. It does not work with the new input system
Best I could do is patch it with the old input system by listening in for a "\" key (to open/close the console) and the return key to check the input, but then only if the input field is not selected.
What am I missing?
Before you suggest it, it's been 3h of me watching every possible tutorial on the new input system and they all have a different method, both between each other and from what it's in this video
By this of course I don't mean to put down the work you've done, it's a very well thought and cool tutorial, which is one of the reasons I subscribed to your channel. In my opinion it's missing a likely trivial but critical passage that I can't seem to find
@@LeoninMinecraft Actually yes. I'm going to copy down the process and code I use right below.
• Create a folder in "Assets", I usually call it "Input" or some such
• in there I go right-click -> create -> InputActions. I do not generate a c# class for it
• I pin the Input Actions menu near the scene/game tabs and fill it with the maps/actions/bindings I want. Remember to save it
• on the game object I want listening to commands I add the Player Input component, then drag&drop the InputAction asset created before in the first slot, choose the actionmap I want the game object to be obeying, and as for behaviour choose "Invoke unity events". The rest I leave as is.
This is all the "prep work" I go through, the rest is done by code
using UnityEngine.InputSystem;
public class DebugController : MonoBehaviour
{
private InputActionMap actionMap;
private void Awake() {
actionMap = GetComponent().actions.FindActionMap("Debug"); // "Debug" is the actionmap name
actionMap.actions[0].performed += OnToggleConsole; // I only activate the toggle console trigger at first
// it's not optimal, but I grab the actions from the actions array in the actionmap. VERY dependent on the order
BuildCommandList(); //builds the list of commands for debugging - not a part of the input system/actions/etc circus
}
public void OnToggleConsole(InputAction.CallbackContext ctx) {
if (showConsole) {
actionMap.actions[1].performed -= OnCommandConfirmed; //IF I want to close the console, I deactivate the trigger to confirm commands
showConsole = false;
return;
} else {
actionMap.actions[1].performed += OnCommandConfirmed; //IF i want to open the console, I activate the trigger to confirm commands
showConsole = true;
return;
}
}
}
This is the code I arrived to after much cursing and sweat, and it seems to work for me. If you still have problems, do tell and we'll find some solution I hope.
P.S. Technically you should also unsubscribe to actionMap.actions[0].performed when the object you are using is to be destroyed. This way you don't run the risk of triggering some left over code from the trash and crashing the program
@@tobiacancelliere6972 Thank you so much my friend!
@@tobiacancelliere6972 Hi thanks for sharing your code, What's OnCommandConfirmed ?
@@telli5868 OnCommandConfirmed is a function that is called whenever actionMap.actions[1] is triggered.
As this is for a cheat code inserter, I mapped actions[1] to the "enter" key being pressed, as you would at the end of a command input, so that's when the OnCommandConfirmed method is called.
The function itself is merely a string parser to recognise the command on input and looks kinda like this (I don't have the code, new pc):
public void OnCommandConfirmed(InputAction.CallbackContext ctx) {
if( input == commands[1])
Commands[1]();
else if (....)
....
}
Hopefully it's clear enough?
@@tobiacancelliere6972 Ohh yes thanks !
I'm getting an error around 3:15 saying "Assets\Scripts\DebugController.cs(23,5): error CS0103: The name 'input' does not exist in the current context" (also at (23, 74))
any suggestions on fixing this?
Great video mate :) always keen on seeing what dev tools and items you come up with.
Literally exactly what I needed! Keep up the great vids!
How do you get the toggledebug and onreturn functions to actually get called????
really nice Video , Found it really helpful , your are amazing brother
Why would you use a List when you have defined a base type for your commands?!
Math: *is confused by what the "grave accent" is*
Me, a native French speaker: *hon hon hon*
How can I make so when I press the ` key it also focuses on the textfield?
Where did u call the Onreturn method??? pls help
I probably forgot something but when I enter into the text input mode, the cursor is not blinking and the textfield is not receiving the inputText 🤔
Currently having the same problem...
i think we can use for all commends enum class with index, so we can reach our goal basically
Thanks. I hope you continue to make more videos!! Would love to see one for an target box in games like MMO's or RPG's that highlight the enemy with various options or ways to do so. That would be great :)
This is SO GOOOOD! Very easy to implement and flexible. Thank you a lot!
Why are we not using properties here?
can you make an inventory tutorial? all the other ones ive watched or looked at dont make sense or are explained correctly
I've been waiting for a tutorial like this one for ages.
Best unity tutorials by far
Wonderful job, but i just wanted to say that i have adapted the scripts to work with the old input system.
This new input system needs updated tutorials, on how to integrate and even replace previous code.
Would you mind sharing this? I'm having trouble with the OnSubmit aspect. It doesn't seem to pass that key to the Input.
Oh nevermind, I found a comment by Mohammed Omar ruclips.net/channel/UCfSzQ3JjiwmuL0SWMH1uA7Q about how to do it. From them:
"An easy fix for this is to add these lines at the end of the OnGUI function and remove them from the update
if (Event.current.type == EventType.KeyDown && Event.current.character == '
')
{
HandleInput();
input = "";
}
"
I agree with everything you said about testing during development. I have said this years ago that the reason for codes and console cmds is to test the functionality of the game. Who in their right mind would play the game to level 99 just to test it.. let's skip.to that level and test it
This is a good channel. Sadly brackeys stopped their channel but this is a great alternative!
What should I do if I want more actions on a single command (e.g. give itemID itemAmount)?
Hey! Great video, i just have one question, at 3:49, is there a reason for not simply using {public get; private set} instead of the extra variables?
Personal preference around readability. Habits formed after working on teams with shared code over the years. Making a private variable, and a public getter is much clearer and faster to parse on large projects in my experience.
6:40 most important part of the video.
4:20
Im having problems with the Action command, it says that the type or namespace "Action" was not found.
put "using System;" at the top of the script
could you release the code? it is a bit too hard to follow as you are going so quick
4:40 how do you avoid the error "you are trying to create a Mono Behaviour using "new". this is not allowed"?
The next Brackeys here for sure!
Bruhhhhhhhhh I literally just finished doing this and then Game Dev Guide releases an awesome video on how to do it.
thanks for the guide man, Keep it up ♥
It would have been great if you had explained how you did the actions or at least what parts of the code you should skip if you want to activate it another way.
Worth knowing: It's the ` (grave accent) for UKers, but that key is ~(tilde) for Americans, and every now and then a game will code it poorly and so trying to type an apostrophe will open console.
How would you go about that suggestions/search thing you mentioned in the end?
this is perfect. Good job
Nice idea. I had a similar one, where i am able to mark a method with an attribute [ConsoleMethod("name", int additionalParameters, etc...)]. With reflection i just managed them in a list, like you did. That way, i dont have to manage the list manually, but of course i do have more computional cost at the beginning.
I actually used something like this for commands of a cli app. It'll be real flexible but yea, reflection with take quite a bit of performance for loading, tho i think it's worth it.
Hey, I know this is a very old comment but I'm trying to implement this as well but I've never used reflection before. I made the attribute and got all the methods with that attribute, I just don't know how to create DebugCommands from those methods, like how to create the generic objects and use the already existing implementation of the method in the action
Dude, this is beyond average. Thank you again for sharing.
Can I find the code online? I don't get why you wouldn't put it online.
how do i make a command that has a string as an argument? when i try to change DebugCommand to DebugCommand nothing happens.
Can u give me the source code cause I dont understand it at all
It keep giving me in error
I'm having an issue where you have to click into the box to enter text, and click out of it to submit the command. Is this normal?
This isn't an issue at all. That's because I assume that you are using the old input system where the input not associated with global events like the new input system
An easy fix for this is to add these lines at the end of the OnGUI function and remove them from the update
if (Event.current.type == EventType.KeyDown && Event.current.character == '
')
{
HandleInput();
input = "";
}
Can you make video on best way to update information in UI?
Now how do we use arguments in this?
There's a nice package called InGameDebugConsole that does this for you.
Hi, i've found it but i can't find where do i bind the key to open it ?
Please guide me on how to have the autocomplete working with this console.
Well, whenever you type a new character in the input (check the length of the input string) search your list of commands if they contain the entered letters (command.Contains(input)) and then just display the list of fitting commands on-screen. Then if you click on an entry from that list just execute the regarding command. You can of course advance this with more functionality if you want, but that should work pretty well as foundation.
I need help... How can I increase the font size? It looks very small
The input just doesn't work for me
Same, I am working on it. If I get any result you will be informed.
Mentions rosebud. Receives a like and sub. Ultimate RUclips cheat code.
How can we activate directly text writing before clicking to panel? If i open the panel, to write, i need to click it. Is there anyway to make it writeable as soon as we open?
I dont know if I missed it but where do I put the scripts and the Input system is it on a empty gameobject?
every time i try to fix an error, another one pops up. i dont have the input system in my version, (or at least i dont think) and if i try to switch my project version to a newer version, everything gets corrupted. please help!
Having trouble adding strings instead of ints, I dont know how to properly invoke it. Anybody got any ideas?
I didn't understand most of the code but it works so im not complaining
Am I the only one where who gets errors because of the Action Object?
Is Action a class he created in another tutorial? I have an error because of Action, the type or namespace name "Action" can´t be found
add using System; at the top of the script
How do I move console to the bottom of the screen?
Crap, I know this is kinda unrelated but I just have to share my pain... I was going to a unity project I had in the windows file explorer and pressed CTRL + D for duplicate. Turns out it deletes the folder instead... and I have automatically clean Recycle bin on.
good work, well done.
Hi there, thanks for this amazing video. I have the system working, however when I press the backquote key to open the console window, the command I type gets a backquote symbol (`) in front of it. How can I prevent this? Thanks! :)
Confession: I know nothing about the Input Actions system and have no idea how go about finding it.
Feel silly but found out. Had to go to Package Manager and install the Input System.
2:45 LOL Nice Edit XD :D :D
i am very confused i have like 75 bullion errors and no idea how to fix them
If i think how much I struggled to manage glyphs,shaders&co for embedding text in quake style console in c++ with opengl I start crying..
Hello there is no action Thing in my code when i write it i get errors
hey there can you please help me to make small command for me? what i want is i press key command panel opens and i type then hit enter then should return string what i typed in command that's it if you interested to help ill provide you plugins
Do you have the project repository?
Scriptable objects would make this awesome
Just a quick question, I know how to use the inputSystem with the "CallbackContext" but, how do we use the "InputValue"? I never see where we could use it....
InputSystem supports different types of joysticks and gamepads. So sometimes you may need a particular value of for example an x axis of the left stick of PS4 controller when callback happens. That's the situation when the InputValue makes sense
thanks game dev guy
here is add. If you write set_gold / with space after command it will be parce exeption. Also if you do not check count and write just set_gold. If you need here is solution private void CheckCommand()
{
if (_showConsole)
{
string[] properties = _input.Split(' ');
for (int i = 0; i < commandList.Count; i++)
{
DebugCommandBase commandBase = commandList[i] as DebugCommandBase;
if (_input != null && _input.Contains(commandBase.comandId))
{
if(commandList[i] as DebugCommand != null)
{
(commandList[i] as DebugCommand).Invoke();
}
else if (_input != null && commandList[i] as DebugCommand != null && properties.Length > 1)
{
if (int.TryParse(properties[1], out int value))
{
(commandList[i] as DebugCommand).Invoke(value);
}
}
}
}
_input = "";
}
}
Nice video! Could you make some tutorial about spell system on RPG? It would be great!
Can you put your project on Github sir?
Also your videos are great!
I did the same thing and it doesn't react to the ` press
If you are using the old input system, it's called KeyCode.BackQuote. For the new input system, make sure it's the current active schema
Hey could you please do a Tutorial on car Traffic
Thanks!
Next step: Make manpages, so the user can find all cheats
Super useful
Is there a way to get the code?