UE4 C++ Tutorial - How To Use Debug Helpers - UE4 / Unreal Engine 4 Intro to C++

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
everyone and welcome back to another Unreal C++ tutorial knowing how to debug your own code or that from other people is going to be one of the most valuable skills that you can learn when programming and unreal provides a number of ways to do this in C++ and in this video I'll cover some of the main methods that you generally see used so to begin I'm back in my example actor class and I'm just going to declare a few different variable types and expose them to the editor to demonstrate later in the code file I've already shown one of the most common types of debugging which is logging and I kind of brushed over this in the past so we can take a quick look at what this is doing so in short this is just writing a message to the output look we have a few arguments for the basic override the first is the category which will usually sees that to a log temp which is simply creating a log message in a temporary log file next we have the log verbosity which will control a few things here we can see that this is set to warning which will print this as a yellow warning message other examples could be things like errors which will flag this as a read error message and then another one even more serious than this would be a fatal log and this would be really useful if you wanted your game to crash out if certain conditions are ever met when I say use he crashes aren't great but this will help you if you ever think there's going to be an issue which might be in a build if something enters a certain part of code then you don't want that to be missed by QA teams or just general play testing so having it completely crash out with a fatal error can be really useful so you can track exactly where that happened and never miss that happening so there are some of the things you get from log verbosity there are a lot more of these available so check out the documentation just google log verbosity unreal and you'll find all of that and then finally what's being written here is the tech and that's what's actually being written to the log here I've just specified a predefined message which can be useful to confirm a function is fired but we're gonna take a look at how we can build on this with more dynamic results so I'll copy this into the begin play function so that it gets called automatically as soon as the game is starting then in the next section I'll update what's being printed and we can then override the text with an argument taking in a value in this case I'm going to use the debug int that I've created earlier and do this you need to place a percentage sign to find where you want to print the value of a variable in this case is going to be the integer which uses a predefined type value D to specify that we're printing an integer we can then place a comma outside of the brackets followed by the variable name to print that to the log we can also see how this is done for a float and a string variable too so the float is very similar but instead of a percentage D we're using the percentage F for float and then finally for the string it's the same thing again but instead of those percentages as percentage s for string this time we do also need to place an asterisk in front of the debug string variable to dereference the F string when using an unreal engine log to a standard C style teach our pointer I've also just realized that for some reason I've declared all of the variables as visible anywhere so I'm just going to go back and change that to edit anywhere so that we can actually change them in the editor so I've compiled this and we can return to the editor to see the results with the play mode set to simulates we can see the in the log section that the variables are all printing their default values that I've given them so that's kind of what we hoped I'll then press and exit play and change the variables to each have some new values then pressing simulate again we can now see that this is printing the new value to the log section so this can be really useful to find out what's actually happening two variables during play and track down any strange behavior from them so that's the first type of printing that we'll usually see when debugging in C++ so next back in the code we can use an add on screen debug message which is going to be the more familiar type for anyone who's seen a print string in blueprints so the first argument here wants a unique key to prevent the same message being added multiple times then the time to display on screen in seconds we can pass in a display color and finally the message to be displayed which I'm just going to copy from any of the Yui log examples and then to use this in the same way that we did with the the log taking in a variable to be printed we need to prefix this with the F string double double colon print F and this is called from the G engine the G stands for global so this can be called from anywhere again I've compiled this so I'll return to the editor to demonstrate the new on-screen message now this type of debugging can be much more useful for quick and easy information feedback during game play compared to logging which usually requires you to read back through after you were playing and connect what might been happening during the certain points of play so that was simple as I said can be used very much interchangeably and in the same sort of ways there's not too much to go through there so moving on to the final type of debug helper we'll be looking at is one of my favorites and they are the general types which allow us to draw things like text or geometry in the world and this can be really great for seeing exactly where something is hit or will be placed or spawned in things like that in the world so to begin for this one we'll need the include drill debug helpers library then again I'll call the function in the begin play and I'm just going to draw a simple sphere but like with anything else you have plenty of other options you can draw things like cubes circles crosshairs and much more if you look under the draw debug helpers documentation section so this has several overrides the first is the world contact so we can just use the get world then we want the center location vector so this is why it's going to be drawn around for this example I'll use the actor location plus an F vector offset to place it somewhere just to the top of the actor usually when you're using this this would be the location of a trace result of something and then we need to pass in a radius so how large the sphere will be I don't want this to be larger than the 100 unit cube so I'll give this radius of around 20 units which will still be plenty visible next we have the segment's option so this is hide detailed at the sphere will be we don't want this to be too high for performance reasons but again 20 segments should be fine I'm going to make the sphere drill in orange and then set the lines to be persistent I provide this a life time of a hundred seconds so that I can still talk whilst it remains on-screen and the default depth priority is usually set to minus one so I'll just stick to that and finally the line thickness I think somewhere around two usually works quite well and the name describes what this will control so if those changes made again I'll recompile this and go back into the editor and here we can see our lovely little orange sphere and it looks as though I could have done with some fewer segments it's a little bit cramped but it's that two hundred units above the actor as we expected and it's gonna stay on screen so all of that's worked as well and hopefully this visualization of something immediately shows the kind of use cases this can have and how this will be useful so for example this could be used for something like checking where traces such as line traces are ending or beginning checking projects our impact points in situations like parkour systems you can have this checking exactly where the player makes contact with the wall if you wanted to visualize this to see if you're being too lenient or too hard things like that so without done be sure to leave a like if you enjoyed the video or find any of these techniques useful and remember to subscribe and hit the notification bell if you wanted to be kept up to date with any of the contents or tutorials that I release on a weekly basis as ever though thanks for watching and I will see you next time
Info
Channel: Dev Enabled
Views: 5,160
Rating: undefined out of 5
Keywords: devenabled, devenabledUE4C++Intro, gamedev, game dev, game design, tutorial, tutorials, unreal engine tutorials, ue4 tutorials, unreal engine 4, ue4, pluralsight, course, learn, education, ue4 content, audio vis, audio viz, unreal audio, ue4 audio, game Mechanics, ue4 C++, unreal C++, unreal Engine c++, ue4 C++ tutorial, unreal engine 4 C++ tutorial, debugging, debug log, ue_log, debug sphere, debug helper
Id: pmMjIAoCmMg
Channel Id: undefined
Length: 7min 31sec (451 seconds)
Published: Tue Jun 09 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.