Creating a Cheat Console in Unity

preview_player
Показать описание
Learn how to create an in-game console that will allow the user to input cheat commands. Perfect for debugging builds and hiding fun easter eggs into your game...

--------------------------------------------------------------------------------
Want to support the channel?

Use these links to grab some cool assets from the asset store:

--------------------------------------------------------------------------------
Socials and Other Stuff:

Рекомендации по теме
Комментарии
Автор

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 YouTube. 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)

PhodexGames
Автор

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.

goldkat
Автор

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 then simply use that name with GUI.FocusControl("name");
Your cursor will automatically be in the field.



input = GUI.TextField(new Rect(10f, y + 5f, Screen.width - 20f, 20f), input);
GUI.FocusControl("console");

ColdOneK
Автор

I've struggled a lot to find a good tutorial on cheat console and this is the simpler and best tutorial on it!

Pedro_Marangon
Автор

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.

CirbyWeh
Автор

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.

Madalaski
Автор

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!

ShiloBuff
Автор

Could this be the single most important tutorial ever made? Leaning strongly towards 'yes' here. Thank you, Game Dev Guide Guy!

mad_man_
Автор

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.

KGofMaul
Автор

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);
}

efekaanaltas
Автор

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

PeterDanielBerg
Автор

Nice video but mother of god the whitespacing at 5:47 I'll never forget

TheCellCH
Автор

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.

jbaidley
Автор

Nice work! I love your tutorials! Will deffo be adding this into my game :D

Dkryption
Автор

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.

KyuVulpes
Автор

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!

vitiet
Автор

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.

rib_rob_personal
Автор

One of the best Unity channels on Youtube. 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.

WesleySales
Автор

your videos have by far the highest value on YouTube. 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 YouTube), 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.

adammed
Автор

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?

InsertName