Unreal Engine 5.2: Basic Structs and Enums (In Depth)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey everybody it's Randy welcome to another data structure and data variables video in Unreal Engine 5. uh so last video we kind of went over the different types with the basic types you know Boolean byte all the way up to text but we didn't cover Vector rotators transforms structures and enums so that's what we're going to do today now I will give a forewarning I'm no expert in physics but I do understand how they are actually transferred though you know vectors rotaris and transforms to computer science and specifically the Unreal Engine so if you want to create them again you go in here and actually select them and when you go over to the actual variable itself you can see we have an X Y and Z and that's the like a like a graph like a 3D graph the X Y and Z location with the Rotator it's very similar it's the X Y and Z rotations um and then the transform is a combination of a vector a rotation and a scale now if you've done Unreal Engine before you'll know scale if you go here and you can actually uh here we go so if you go to smash this is the transform of the object let's actually go to the mesh itself and so if you increase the scale it's just like blowing it up um and you can do that in the X you could do that in the Y you can do that in the Z and then again the rotation this is the X the roll and so you can see it kind of rolls around the the pivot location there around its origin specifically uh the pitch which is like this that's kind of like the Y the pitch and then you have the Z which it rotates around it like that and then you have furthermore the location which is just a 3D space you know you have your x-axis your y-axis your z-axis all of this goody good stuff oh no uh let's go ahead and take that down uh so back to the event graph so if we create one you know we have we can call them here and we can set our x y and Z's to them and then again the transform is a is a combination of a two now if you are in um if you are in Blueprints and you want to actually like get the individual values um you can click on it you can call something like break Rotator vector or transform and so you can see um green and Unreal Engine by the way is a float so you can see here that if we plug it in it's going to take whatever value we have in here and it's going to break it down into the float values the role the pitch and the yaw and the float remember is something that can be represented by a decimal negative and positive and same with the vector here we can break that apart and we can get the individual x y z values and for the transform it kind of kind of does it even further take it in you can break it down to the location rotation scale I can break down even more you break it down like you said here individually and here with the scale um or you can combine them and call the breaks for the vectors in the rotators uh and they're super super helpful you know if you're making a game you're more than likely going to be using them if you find a way around using them you know please please let me know um like I said they're all just stored in values but that's that's the basics of them uh now there are ways you know there's things called vector addition and Rotator Edition uh and I can go over theirs eventually those are those are pretty complicated especially for me I'm not a super big physics guy but I I get the gist of them but uh going from that point on we're going to talk about structures so if you remember in the last video we kind of talked about how the array sets and Maps store individual single values in certain ways you know through a key and value pair or uh non-duplicates you know just table values or a duplicates allowed table of values you know the array and so the structure is like creating your own so I've I've created my own structure here um and what you could do in here is I've already created four variables and so these four variables I've just made a Boolean a vector Rotator and a transform and you can again set these to pretty much you can set these pretty much to whatever value you want which is really really nice um and you can even set the the structure to itself you know a little bit of Inception and so you can create a little two-tip tooltip here what do you want it to be actually equal to you can add more values and you can add as many as you want now if you want to create your own you just go into your content drawer you'll right click and you will go down to blueprints and you'll just create structure give it a name and then there it is so now how do you call this in your actual code well it's just like any other valuable it's it's a brand new value of the game now recognizes Unreal Engine recognizes so I can go ahead and set this test variable for here what I call it a test structure so test struct right here and you can see it and you can see we can even put it into an array but we can't set it into a set or a map or yeah we can't uh but you can see here so remember I created one for with a Boolean a vector a rotator and a transform and so you can store the Boolean the vector the Rotator and the Transformer we can name it whatever you want so I can go in here and then now let's say you want to get the actual specific value in the structure um well you'll just pull off of it and you'll call break test structure and so this breaks it just like it broke the the vectors rotators and transforms and so now you can see you're your Boolean and all that and again you can right click on it and break it or you can recombine it if you drag this over here throw the vector in and I'm breaking it and so let's go ahead and just print it out just so you see it uh we'll go ahead and set this value is that the X just gonna set all of them and we can go ahead and you can see we broke it we got it oh I definitely messed up these arms that's okay uh and so that's how the structure kind of works and they're super useful if you know you you don't want to create a whole new class you still want to store things but you can't store them in anything that's already given well you can create a new structure to store all this and you can pass the structure along you can create new structures it's a really really great feature uh and it's it's in Unreal Engine and it's in most programming languages as well which is really cool so let me go ahead and delete this one I don't need it and so now we're going to go over quickly enums so again uh go to blueprints enumeration is what it stands for uh and we're just typically the prefix for it is uh capital e I'm just going to call it tester enum and so you can open it and add an enumerator so this enumerator we can name it uh hello or actually no we can just mail female this is a better example so let's say you want to um label a character a certain value we want to know if they're male or female now you could have a Boolean um but what if you can't do a bullying you know um so instead of male or female you could say uh what kind of car ORD you know uh master and we'll add another one we'll add uh what's a cool car there's none that's not true Chevy well just do Chevy we'll just do Chevy because that's the first thing you can rewind so okay so we have four Mazda and Chevy because maybe bullion isn't gonna work but we still want to know how what kind of value that is and technically you could kind of store this into a you know a string and then set the string but that's gonna that's gonna cause a huge performance hindrance um because you're always checking the string you're always resetting all the characters with a string versus this is a value and it sees if it's set to that and so what we can call is we can create a new enum look for it what I call it e-tester oh boy I can't spell e tester enough so we can click and I'll I'll go a bit in a little bit more detail on why that's actually faster um oh boy uh so if you see here hey you gotta you got a drop down box now if you can select Ford Mazda or Chevy uh and so this is really really useful and you could do the same thing here you could set them in arrays sets or Maps that's really really helpful when you set them as keys and maps uh or if you set them as values there's more more time I've used them a lot as keys and Maps which are super helpful and you you can print out you know the enum to the uh console or to the screen if you want to actually see it so you can see here boom Chevy you know and so a lot of times you can see you know if a character is passing through you know something call this value and see what it's equal to you know if you if you want only people who like Chevys to pass through let them pass through if you only want people who like Mazdas to pass through you can only let them mess through it's just an example we'll go on so what it what exactly you know is an enum like it just looks like a like an array or a set specifically because no duplicates of streaks and you're kind of right but you're also kind of wrong so what would be the difference of just having an array of strings and strings are just characters like ABCD alphanumeric characters so it'll be the difference of just having an array of strings versus having an enum so an enum there's actually an index kind of similar to an array so instead of like checking because like when you when you check if an array value is equal like if it's another string is equal to this it goes through and if you have the word we'll just use the same example again for some reason uh Ford and Chevy if you have this example when you when you try to see if they're equal it's going to go through and check IS F equal to C no it's gonna fail but let's say instead of uh Chevy we had the word uh or Bordeaux all right so instead it's going to check is f and f equal yes is O and O the same yes R yes D yes no this is the odd one out but C what's it doing though is it's going through and checking every single character comparing it and so if you're doing this a lot like a lot in your program it's going to cause some hindrance probably super negligible but if you're doing it a bunch it will and it's just it's just a pain in the butt to actually write this so instead you have enums so underlying you know we have the enum you know called board I don't know why I'm using cars in as an example um I only have like Chevy and let's say what was the other one Mazda Mazda I like my Mazdas I drive a master so I like Masters so we have like four Chevy and Mazda okay Mazda uh and the way we check instead of going through and actually checking if if each of these characters is the same it's almost like a map they're associated with a number value an index so for you know the for being the first one is going to be Associated one two or zero one and two so if we have another enum coming in and it's equal to uh we'll add we'll add Ordo because that was the example here's before so I have another enum coming in you know Bordeaux and we have another enum and it's equal to board and so we want to say hey you can't come in unless you're you're a Ford well it's going to go through and instead of checking every single character it sees it it's an enum and it instantly checks the index and it sees this is the index three wow that was rough index three is the index zero they're not equal so you're not allowed but we bring in Ford we see it's an enum we see as an index of three we instantly know or not three zero we see they are the same and we're good to go and so that's kind of how enums work and they're really useful for a lot of times like if you have a a first person shooter or third person shooter and you want to store the currents um like physics state of the character so if they're running if they're swimming if they're jumping if they're you know wall running sliding all that kind of crazy stuff enums are a really easy way to store it instead of strings they're very similar but they they are these are a lot more efficient and these are a lot easier to read these are much much easier to read and so I would highly highly highly recommend using them in your program in your in your Unreal Engine your game they're just going to make your life a lot easier storing certain values you know you can you store run um jump and so on and so instead of going through and checking these it just checks the index which is just super super quick you won't even notice it I mean you probably wouldn't notice this that much but this is just way more readable and easier to deal with and you can make them you can make your own uh like up in here pretty easy to make and this is a structure and here now if you look in here you don't actually see the index of them it's kind of Auto done for you however you can move them around um and so you when you when you deal with enums you're not actually like when you're dealing with them in blueprints I should say you're not actually going to see the um the enum value like the index but you can you know see here um let's see yeah so you're not actually going to see that but you can put on another one check if it's the same thing you know turn back um and a lot of times too uh like if you write this in C plus plus and you specify the index number you'll actually see it when you like hover over it but again you just go into utilities you can go into Eno and you can set equal not equal byte to enum um so that is just taking in like a byte number so remember bite um that we talked about before remember how I said this is the index so it's taking in this number and correlating it to whatever index and turning out a correlated enum so if you have the number uh two and we put it in uh we would return the enum Chevy you can also do really cool stuff this is super super helpful if you go down to utilities you can hit select So based on this whatever the value of this index is or the value of the enum you can pass in data and then select it based on that and you can also where is it and um switch there we go switch that's another one I was looking for this one is super useful uh this one I've used this one but most the time I'm using switch and what this does is it sees the index you run in an execution node and based on the execution node uh you will see what uh you'll get a correlating execution so if we come in here we go here let's see so this is equal to Mazda so we're gonna we're gonna print another and we're gonna say bye I don't know and we'll print here and we will print good night I don't know so so we have a set to Mazda right now so What's It Gonna Do Is trigger's Gonna Come in it's gonna see that you uh you have an input of the enum you test your enum and based on that it's gonna flip it kind of like a like a train like a train pack path and switch it to Mazda and now whatever's on this is gonna run instead so if we go in here we click it bye and uh let's see and then if we switch this to board we'll get our typical Hello message uh so yeah that is the enums and structures they're they're pretty simple once you get the hang of them and you can create all this in C plus plus uh and I can show that eventually in another video but uh leave a comment down below uh share this with your friends uh if you have any questions you know let me know I'd be happy to help you and just uh take care guys and I'll see you in the next video [Music] thank you
Info
Channel: Eternal Stellar Games
Views: 527
Rating: undefined out of 5
Keywords: UE5.1, Unreal Engine, UE5 Input, Gaming, Computer Science, Data Structures, Data variables, Enums, structs
Id: sw7XixEqpv0
Channel Id: undefined
Length: 20min 45sec (1245 seconds)
Published: Fri Jun 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.