UE4 C++ Development for VR, Part 1 (Setting Up the Basic VR Character)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so just just a preface this C++ was kind of abandoned at some point maybe like ten years ago as a teaching mechanism partially because it's as complex as it is it's it as a as an oversimplification that basically has like every feature of every programming language that you've probably used as an undergrad it has like the really it has the really ugly pointer stuff from C and the syntax from C but it also has all the really strong object-oriented features of something like Java with some extra things that Java can't do like multiple inheritance and the complexity itself is actually one of the reasons why it's used in such complex systems C++ is usually the standard for really complex api's like game engines and Oh some OS is like the Windows 10 SDK is in c-sharp and C++ and things like that and because it gives you access to pointers and it's you can get pretty low-level it can also be made to be very performance unlike something like Python where everything is an object and so and in any Python program we use a ton of RAM so C++ is great for complex performance systems that need to interact very well and you know run at a decent rate so games have to run at a certain frame rate and you know windows sister wanted a certain speed and things like that it's also used in IOT Internet of Things so you know if you're pairing your watch communicate with your phone and your refrigerator and your tablet C++ and C because they tend to work on most devices are the languages of choices for that kind of thing and even in languages like Python libraries that you may be familiar with like numpy are actually written internally with C++ because it performs so well so C++ is an important language to know but it was kind of just abandon because it was too hard to teach with it you spent so much time just trying to figure out how to do the most basic things that the the high-level material that you're trying to teach kind of gets lost in the details so anyway I'm not going to go over any of the I'm not gonna go over every feature of C++ and I don't think it's worth doing that anyway I believe an example based learning so I'm basically going to be redoing my VR lectures from the 590 class but in C++ so these down here where we did things like have a gun that could shoot we have teleportation we had a bunch of different ways of grabbing things like telepath or telekinetically grab things grab things with your hand of magnetic grabbing things like that and these so in implementing these in C++ I actually find that the flow of these lectures that were done in unreal blueprint system actually touch on details that don't normally get touched on your average YouTube C++ lecture that are actually really important so I don't know maybe it'll be helpful to have this lecture in general also you should note that a lot of so if you decide a study c-plus falls from a textbook a lot of the details are actually not applicable to something like unreal because unreal has its own classes that are wrappers for C++ classes and unreal also tries to stop you from doing stupid things so it disables some of the more crazy experimental features of C++ so a lot of details that you might learn from a textbook are actually not useful for unreal specifically they might be useful for other C++ projects and the only way I think we'll learn best from practice so I guess I guess I will kind of assume that so some people some people who are too joined are from the 590 so they already know how these lectures went if you're not familiar with them it's fine because well I have I still have the original class example from this from those lectures and I will be comparing the C++ through the blueprint that I used but you don't actually need to know the blueprint like if you follow along you might get it you might not but if your goal is not to learn blueprint then it doesn't matter one way or another anyway let's create our project so I'm going to use I'm real 4.24 because that's the latest one that I have installed all those you can stop me if you have questions fortunately I have an i-9 so it doesn't take that long to compile anything nice flex well this it's it's not really a flex because I'm borrowing this machine from the department there's anything it's the opposite of a flex well now it is okay where did my own real window go oh there it is pop up for a second alright so at least for the newer versions of unreal when you start the project you'll get a window like this where you can create different types of applications like unreal has become general enough that it's used for things like movies and architectural visualizations and things like that I'll use games because we're doing games and a lot most of these templates that they have actually do have a C++ version so the first person template does have a C++ version so there's blueprint and C++ the VR template unfortunately only has a blueprint one so that's kind of unfortunate but it's fine because in the original lectures I just made my own dr pawn anyway so I'm just going to expand off of the first person template and I'll use a C++ version and actually just in general if a good way to practice developing in C++ is to compare the blueprint implementation of these template projects to the C++ version if you're one of the people who did the 590 assignments in blueprint that may be the easiest if you know unity then maybe it's not as useful but you know it's still worth doing it's worth understanding how to do the same thing in multiple programming languages in general I'm anyway when you choose a template you can choose between blueprint C++ if it has both of those options I'm gonna make it scalable quality just so that I don't crash something I don't think it will matter with this GPU desktop and console is fine if you initialize a project with mobile or tablet it creates these little joysticks so that if you build on a phone and push it to a phone it would already work with the joy with the touchpad you read out these joysticks that you can pull and it'll just work but we don't need that scalable to the ray-tracing disabled I'll use the starter content simply because I want to use some of their materials the starter content has some really simple meshes like chairs and tables and materials like metal and wood and I don't know if it has anything else I mean it knows like the textures that you would need for those materials like it does with textures I think it has the skyboxes and things like that but let's not worry about that I'm gonna call this project you we've just a ue4 c-plus created and if you so you need Visual Studio to compile anything in C++ and unreal if you installed the engine you probably installed Visual Studio but if not I believe I already have Visual Studio installed so I actually don't need to worry about this but I believe if you don't have es installed at this screen it will show you a little message at the bottom saying you need to install yes and it will give you a link that has pre configured on real settings which you can click and install with so yeah the u.s. takes a little bit of time to install as those unreal so you want to do those well before a deadline at least but afterwards it's not so bad well they're both they're both pretty hefty applications I mean they both use a ton of RAM like vs is actually pretty good I have a different BSP project open yeah I have two Bs projects open but you can see they both use like a couple hundred Meg's of RAM the unreal unreal always uses a ton of RAM it's a ram hog like Chrome there's not really not much you do about it and Epic Games launcher itself is a piece of garbage so I'm just going to close it so I use the first person template and the first person template in C++ and blueprint looks the same the scene layout is exactly the same the difference is that oh this isn't even oh this is it okay I thought it was I thought I had the other project open um the only difference is that the character is not done in C in blueprint anymore so in the original demo you had oh this is the VR template I'm in the original version of this app you had something called motion control or pong at least in the VR template you had like a motion controller pollen and it had a bunch of pre-built blueprint code that you could use for various things the first person character has the same thing in blueprint now let's in C++ so I'm gonna you can click here to edit and the only thing that I believe has code right now are the first person character and his bullets you can see your own C++ classes that were used for this project down here if your if you have a C++ project that will create this folder for you that has all of your C++ classes so you can see it has the character which corresponds to this game-mode and their projectiles this is the equivalent of these files in the visual studio project that opens up so you can edit these in business visuals donor here you can open them up you've header and C++ files which I'll explain in a second and in terms of the directory itself like where it is located in your windows file system or Mac file system you can just like with blueprints you can right-click any of these and go to show and Explorer and it will show you where they are in Windows Explorer so the main difference between a blueprint and C++ project is that a C++ project will have this extra source directory which has your C++ code and it also creates a visual studio solution in a regular blueprints projects like this one you don't have those you just have the u project which is what you use to open the Unreal project build I made myself and these other things are the same between C++ and Brianna so a C++ project adds these two things so anyway moving on we I'm going to create my own VR VR class I'm not going to use their first person character but just to introduce you a little bit to how C++ works this first person character okay they have a blue coloring here where it says type so that means that it's a wrap apply a blue print right now but you can see the blue print actually doesn't have any code it's only being used to position things the actual C++ class is here and in C++ it's very similar to C where you have header files and body files in the header it's pretty good practice to put all of your include statements in the header itself in unreal specifically you have this dot generated H file which the engine itself generates you should never touch this and it also needs to be the last include but that's a detail that's not that important if you don't have this as the last include it'll throw an error so it'll be obviously you don't the header also includes the basic class information so here we have a my project name example character which is this first person character it is extending a class and unreal called a character which is okay so a character is a subclass of a pawn a pawn is an actor that is meant to accept any kind of input like it's an NPC like some kind of player of any type it can be an AI player it could be yourself a character is an extension of a pawn that can move and has physics information I believe those are the two main things that it adds but it's not really important because we're not going to be using it for these tutorials just like with any other programming language like Java or C you can right-click on these things in the IDE and go to like the information about this class so for a character I can right-click it and say go to definition and it will show me the I can go to the engine definition of characters if I want to see what is being inherited but enough of that because we're not going to be using character I'm gonna move on generated body is something that unreal throws in there and the header will also include variable declarations and macros which we'll see more of soon in C++ you don't say when you're declaring something like a float here you don't say public float based lookup great instead you have a public section like this and everything below it until the next section will be public and you the commenting is the same as in Java or C and you have public and protected and private which you already know all that really changes is the structure so you know you have these sections instead of public void or whatever this class is very complicated so I don't want to get caught in the details because we're not going to be using it so this is the header you also have a body file and C you just have a dot C file right in C++ C PP but they serve the same function they are the body of your functions they are the actual code so here is the constructor which you can use to initialize a bunch of things again I'm not going to get caught in the detail of this particular character because it's not important to us you also have each of the functions so like begin play was declared in the header here it's a virtual function because this is a subclass of actor which has it begin play already so you have begin play and then all the other functions are defined here and it's different from its C style so instead of wrapping everything inside of like curlies for the entire class in the c++ way of doing things you do it this way instead see you have the return value then you have the name of your class and then you have the function name and then the Curly's so things are declared like this instead of you know being encompassed in one giant set of curly brackets like in Java if you have any questions about that you can ask but I don't want to get caught in the details of this character I just want to show you the structure so moving on I'm gonna ignore this class completely and just use my own pond so I want to also just so you know the first person character class it's this guy that you can walk around and Eze across physics accuracy but again we're not using this guy so it doesn't matter I get rid of him I want to make my own class so here at add new where you would normally create a blueprint class like if you were in content you can create blueprint classes and materials and things like that if in C++ classes you can do add new C++ class and you have some some options for the basic classes and unreal you have your character which I mentioned is it's a poem that can walk around and it has some physics stuff a pawn is just anything that can it's just anything that can do anything it's like anything with intelligence I guess although you can have some really dumb NPCs so I don't know if intelligence is the right word it's just something that can be controlled like an AI is controlled by itself in its logic you can control your own pawn and things like that actor if you recall is the very it's the most basic unreal class that has a 3d transform it's is it's basically the equivalent of unities game object components are actor component is basically the same as a component immunity like a script that you add to something a scene component is a components that also has a transform relative to the parents and then you have other things like the HUD it's not important because or it's not important for this lecture because for the sake of following this original VR lecture it's really not worth going over I'm you can also click show all classes to show every single class that you can possibly extend from the engine anyway moving on and not getting caught in the details too much I chose pawn because I just wanted the most basic VR pawn that you can have I'm gonna call it I want to keep its name the same as what I used so in case I have to copy code VOR cpp pawn and this is the name that I gave it if you have modules like plugins that you're creating for other people to use you will have other options here but here it's just run time because it's just my game you can choose public and private if you want to what this will do is split the source directory into instead of having all the cpp and header files in the same directory it'll split them so that the header files are in a directory called public and the CPP files are in a directory called private the reason being that if you're trying to publish code for other people to use you want them to see the header file so that they know the definitions in your class but maybe not exactly how it's implemented and the CPP files would get compiled into like a dll or something that other people can import without seeing your code it's like if you want to make your code private like if you want to make code for people to use but you don't want them to see how you did it you would do it that way it's like how Java compiles itself into objects and you know hopefully you know more or less why you would make code private anyway I'm gonna create this class and it will do this where it creates the file and then it compiles it for the first time you can do this in a blueprint only class as well so just Soria is not actually here but I mentioned that this was a blueprint only class you see it doesn't have a lot of source or a solution this is a blueprint only project you can turn it into a C++ project by simply adding a C++ class so in this project you can do add new and then there's new C++ class and once you create your first C++ class it will create the source and solution files for you I'm anyway here's my vr CDP pong you can double click it and to open it just like in unity when you create a script it will auto fill it with begin play and start not the constructor because the constructor is not useful in unity but just like how unity auto fills things that begin play and what does it call the unity unity has start and update right so unity I started updating it auto fill some empty functions unreal and C++ will do the same thing so it creates a header file for you that has just these things and then it creates the body I'm just to go over this quickly of pragma once I actually don't remember what this does but you shouldn't touch it it has some basic includes so cor minimal it basically imports the most basic things that you need to get an actor working in unreal and because I'm extending upon it also includes the pawn class unreal so unreal c++ is it has kind of specific naming conventions that it likes to use so anything that is a derivative of an actor gets preface with a or yeah it's prefixed with a and so a my vr CP he pong I called it only this but because it's extending an actor they added the a for me I guess it makes sense look makes your code look kind of uglier than it needs to be but that's the way that it is things that are not actors are usually well things that are things like components usually start with you so are game objects hmmm maybe everything that's not maybe everything that extends in and unreal class at all starts with hey I don't remember exactly their naming convention things like enums I think always start with EEE things that are not on real class to start with you or something like that um it's not really important because they handle this automatically so they have this class definition so you've the actual class header is pretty similar to what you would see in Java they add this macro u class right above the class which is used to tell the compiler that this thing will need to run inside of the game engine if you remove u class what will happen is that you won't be able to put this into the scene like right now I can throw my pawn into the scene and it doesn't do anything but it is there if I remove the new class it won't work at all with P 3d scene like I said it automatically generates this generated body part it creates a the constructor which is public it protects they begin play method because really nothing nothing should ever call another objects begin play this is something that's part of the actor lifecycle and tick technically nothing should called tick either but or either of these functions these are probably all be protected but anyway it automatically made it public anyway this is the header file and it has these default functions declared in the body file you can see that they create the functions themselves and their bodies so the constructor doesn't do anything except tell the thing that it can tick begin play doesn't do anything except call the parents begin play tick doesn't do anything but call parent tick and so on we are going to move on to things that are more interesting than this so the VR pawn maybe I should show you what we're actually trying to create first so we are trying to create this demo that I made in class in blueprint where you can do things like shoot and grab different objects you so test this I can shoot a gun and it will turn these little blocks different colors I can grab things well I can teleport around by clicking I can grab things like this and throw them I can use force grab to grab things we had forced grab that snaps it to your hand and there's also a fourth scrap that keeps it out of distance and there's a magnetic grip which grabs the closest objects to your hand and the last feature was that you can shoot the blocks so I can grab something put it on my gun and then shoot it my triggers are barely working this couture is freaking but shoot blocks and so we're trying to create this except in only C++ this was the class demo that I made to show some basic VR functionality so we're gonna try to create this put this out of the way the first thing we need to do is create the VR structure so you will remember if you were in the 590 otherwise you should look at those lectures but a VR character has a very basic structure of there is a scene component which is the tracking Center so if you're using a vibe it'll be the center of the Guardian when you do room setup if you're using an oculus it'll be the center of the Guardian I don't remember the I it is not called the Guardian I don't remember what it's called the oculus is called the Guardian but it's just like this grid that you put around you to describe how big your physical space is so that you don't run into anything so the VR tracking Center is just a single points that describes the center of that area I can show you actually so here's steamvr this way VR view you may not actually be able to see you anymore you said this thing I think they removed it there used to be this thing where you could see the entire setup of your space but you can't do it anymore I guess anyway the tracking Center is the middle of your tracking space the camera is where your your head is as the user so you know where the headset itself is in the space that you are defined and siblings of the head are the two controllers and unreal these are motion control components see motion control component and you have a left and a right control and blueprint is very easy to define these because there's there so you have motion source left and right you could add these very easily by just doing add component motion control and c++ we'll see it's not that easy but anyway this here is the most basic VR character structure and in my class demo I also added a bunch of other stuff which we will try to replicate when you create a blueprint class like if I create a blueprint version of pong it actually creates things like the default route for me in C++ it doesn't do that they're not as friendly I should have kept that that's example the C++ version of pawns are not as friendly they literally have nothing it is quite literally just an empty class that doesn't even have a transform alright yet because I haven't defined this I haven't defined any kind of route for it so we're gonna have to do that ourselves so we will do that in the header so here I'm gonna put the protected part down here just so it doesn't get in the way I you know I don't really care if it's protected I'll just make everything public as God intended I need to create these things from the class example so I'm going to put these side-by-side just so you know what I'm trying to do okay first thing is we'll need a vr tracking Center and this is a scene component in in C++ the you the C++ name of things is pretty close to what the blueprint name for them will be just with this naming convention of adding a or you or whatever so we are going to use a the C++ scene component the the scene component is called it does start with a u so it's a UC component star and star because from 590 I mentioned that Paul components are always pointers because unreal doesn't like when you handle these things yourself like you can't you can't make it an object like this because unreal handles the initialization of components itself so this will be a pointer and it's using components I called it we are tracking Center so it's already complaining but that's fine it's just compile it quickly before I add anything else to make sure it actually compiles it's probably going to get upset that I didn't import something but we'll see in a second now I guess scene component is part of core minimal or poem so there's a vr tracking Center then we have au camera components its bow I believe in camel case so I don't know why I capitalized things when I was doing this but it's so important this we do need to import you can figure out where these imports are located by simply searching for them unreal Jean line documentation is pretty good so the camera component for exemple I looked it up and it tells me it's hierarchy here it also tells me what I need to do to include it so here's its include and here are all the functions and variables and stuff so I need this include to get this import so this will add my camera and now it's green which means that it found it I need to add other things like I do want this one output text so that I have something that's attached to my face that will print things out because if I'm in the VR I can't see the log so this is au text components or text render components [Music] this I also need import what happens to already know that this is the import for it then we need the controller's you motions for components how nice a visual studio to finally autocomplete things you motion toward components this you import through here the only reason that you can import this so simply and we'll actually see this later because it'll become important later is that by defaults in the bill dot CSV file they include this library called head mounted display which has all the information that you need to import the motion controller stuff that's related to the art so you must control our components left controller and you need the right controller as well still not happy about something ah [Music] I have yet another important I need oh wait now it found it Visual Studio sucks oh you don't have a choice but to use it also the I don't know I mean there are settings in Visual Studio that are supposed to make it work faster or like autocomplete faster it uses this thing called at Ellison's which is not intelligent at all I worked on hundreds of C++ projects and I can probably count the number of projects set intellisense work correctly on on one hand but you know that's how it is I find that it's bad in the headers but it's usually okay in the bodies anyway here are these controllers oh by the way you can compile by doing this you can right-click the project and do build rebuild us for if something went horribly wrong clean is basically rebuild is basically clean plus build clean deletes a bunch of cache files built will rebuild them or it'll build them and rebuild will just do both of these in sequence you can also build it from up here but I find this to be faster because I can right-click and do it quickly anyway moving on I had some meshes you static mesh components rag on my giant rig on I had he left cone and yes I know that the capitalization is incan or it's very inconsistent but I'm just keeping it like that so that it's so that this entire lecture is consistent with the class lectures you static mesh component I don't know if I need I don't know why I chose this one specific part to complain about it highlighted it blue though so maybe it'll be fine otherwise I dunno the import that I need for this yeah I guess static mesh component is also in core minimal alright so I have declared these but as you'll see in a second that really doesn't mean anything at all so well okay if I drag this in first of all you'll notice that it didn't do anything I don't see any of those things here but more importantly yes I did declare these things in blueprint but I also handled their parenting structure so let me first let me explain the first problem why you don't see any of these things well there are two reasons the first is that to get anything to appear in the editor you need to use macros like you class which is for classes for these things which are variables basically you have you property so I'm just going to copy this from another project you need to add a new property like this right above the thing that you are trying to add so you property is a macro that just exposes something to the interface in this case I used a couple of I used a couple of options I used edit anywhere which means that I can edit the information for this object inside of blueprint inside the editor anywhere blueprint readwrite means that blueprint can actually see and edit these things inside of an actual blueprint and category just categorizes it so like for this thing here you have categories like defaults override settings rendering these are all categories so you need one of these for everything that you want to expose to the interface and I want to expose all of all of these things in here to the interface so that I can actually use them and when it turns purple that means it's good look at this delay it's like the worst possible autocomplete and this is a fast CPU so I don't know why it's so bad anyway it compiled and this will kind of solve the problem we can at least see these things now inside of this category that I called hide but they're not in the structure here I want them to be here so that I can move them around as I want and you know edit them like in the blueprint version of this VR class from the original lecture I get a structure like this and if I want to move things like my output text I can do that easily because it's here and I can just move it and so I can't yet do that in the C++ version yet and there is a reason for that first of all something to think about is yes pretty much all the components that you're going to be using are pointers but how you differentiate between a pointer to a component that this actor actually owns such as these like this Nick Veerappan owns these components versus something that is actually a pointer to some other component in some other class as far as the header goes you actually don't know that but there are some functions that are built into unreal that are used to initializing and handle the ownership of your own components and also handling the attachment so like you know the actual parenting structure like had as a parents of head and the motion tours or parents of the tracking Center that's the most basic the our character structure the text is out is a child of the head so that when the head moves around you always see this text in your field of view and things like that all of these things you need to handle in C++ yourself in the constructor so the constructor is here and the constructor handles everything that needs to happen before the game starts such a setup and it's called whenever you can pile or whenever you throw an object into the scene or also the beginning of the game the Unreal compiler is or the Unreal constructor is a lot more powerful than unities because you can also use it to interact with other things before the game even starts like I don't know I have a good example of this probably not in this project but let's say that I wanted let's say before the game started I wanted my C++ class to find all of the pickup cubes all these pickup a bowl cubes that are in the scene I can do that in unreal very easily with the constructor but unity I think they try to discourage you from interacting with other game objects in the constructor but anyway those more complicated uses of the constructor we won't see but what we do need to do is initialize all of these things and handle ownership and attachment so the way you do that is with a function like this so I'm going to copy from another project so I don't have to type it all out all of these things that all these things that I declared I need to initialize with this function create default sub object which will create an object of this type and of this name and it's a sub object so it's attaching it to myself so that this actor is the parents of all these things and so you absolutely need to do this otherwise you won't have those things you won't have any of these components let me delete this you might have already noticed I've already worked so it did add these the parenting structure is not right yet and there can only be one route which is why it already chose the VR tracking center as the route simply because it was the first thing that was enabled or that was created um and there can only be one route I didn't actually do that but it is supposed to be the route so that's fine um anyway you can see it actually did add these things and now that I have a routes that is a 3d object that's exposed I can move my pawn around and I can also move around each of the sub components which are down here for whatever reason it decided to put everything below the actual route this so the only thing that I can see right now is the camera and the text because when you add these things normally they have some visualization already and text always initializes with the text but I can't see anything else all the meshes and things like that are empty and sure you could just initialize them here like if I want this to be a cube but the problem here is that if I ever if I ever delete this character this cube was not created as part of the class definition so if I could delete this character or if i respawned them or if i add new network characters they won't have this cube so we need to handle this in the class definition but one problem at a time first let's create this parenting structure that's right here so to do that I put this back here to do that I'm gonna delete this early to do that we have this function called set up attachment so again I'm gonna copy this from my other project just so I don't have to type at all these things don't exist yeah these should anyway there is a function called set up attachment which basically parents this to this so the head is a child of tracking center the text is an ALP is a child of head and so on and so the set up attachment function just handles this entire parenting structure and even though visual studios visual studio complains about a lot of things I honestly don't trust its errors at all it's much easier to tell if you have errors by building the project then to try to figure this out sometimes it works rec they sometimes it doesn't and it really is just random but anyway I have set up attachment so that it creates the structure so if we look back into the project I throw this here yeah I have the structure that I want see with the exception of these texts that are actually not useful I made these after that lecture we do have this parenting structure here so yeah that's one problem solved the other problem is our meshes very quickly I want to mention that the when you create a C++ project it creates this extra button up here compile compile so this it's a little bit weird and inconsistent compile does the same thing as right-click build does here and you can compile things from the editor or from visual studio and which one actually ends up working is really inconsistent and sometimes it breaks for no reason right now if I build this well I didn't change anything this just a force it to recompile so it's gonna recompile it and then I heard a noise and unreal and it mentioned said it hot reload that means that it did actually replace the code that's using right now with whatever Visual Studio just compiled sometimes it when you compile in Visual Studio it doesn't actually update in the editor which is really annoying and when that happens or just in general it's usually easier to just hit this compile button they do the same thing or at least you're supposed to but sometimes they don't I mean it's just how it is C++ is very finicky language anyway moving on I don't have any meshes still which is a problem because I want my Raygun speaking of let me import my ray gun my ray gun is I'll steal from another project contents of Regan's I'm pretty sure my Windows Explorer is messed up so it's not updating immediately but anyway we created ray guns and know every guns and the reason that it's gold already is because in the other project that I was using I told it to use gold and gold is one of the starter content materials but in any case I want I want to handle the initialization of all these meshes in C++ because that's what we are here to do so that I can also do in the constructor as I can do with pretty much any initialization task so I'm gonna put these all mixed to each other and maybe at some point Visual Studio will get rid of these squiggly lines maybe it won't it actually does autocomplete I believe this time it just doesn't feel like it whatever you won't worry about it for now anyway we want to initialize or we want to create the materials so to do that you need to first load the material so if any of you used unity for the 590 assignments euro room you would remember a load object or a blue is called load asset from database or something like that where you can load prefabs and materials and things like that from the editor itself like you can load the ray gun specifically unreal has a function that's basically the same which will do that for you so as an example copying this from another project you have a function like this which will find an object in this case a mesh and load it into this thing that I called loaded object from this path and then I can use it to initialize the mesh for the ray gun you can get this path I guess I'll quit like 6:00 or I'll quit right after I load the meshes and materials I think that's a good place to stop um you can get this path by just looking here so you can see game ray-guns at the path up there also another thing you can do is right-click and do copy reference and paste that here text static mesh I'm supposed to go here yeah constructor helpers we do need to import it is somewhere here here it is it's this imports for constructor helpers I don't remember if you need to import something for static mesh I guess not so this will load the this will load this ray gun into this object but now I need to actually tell my rake on that it needs to use that mesh and I can do that by doing ray gun which is of type static mesh actor why is autocomplete not working for me today by the way those of you who are familiar with si will know this notation for arrows arrows are basically the same as the dot in Java except you use them specifically with pointers like this dot ray gun won't work because this is a pointer to self and ray gun is also a pointer so I can't just do ray gun dot something else you can see it actually autocorrected it for me for things that are pointers which will be the majority of things that you work with you should use this arrow notation anyway I listen to because autocomplete is not working then when I just copy this so here I'm telling the ray gun too set its static mesh to be this thing that I loaded okay so I'll build it and see if it complains I don't think it will it's just being very dumb right now it is done and you'll see the hop reload message and I also heard a little noise and it won't update immediately but in unreal the defaults if you're using something that's not defaults you'll see a little arrow here that's to go back to the default if I click this it'll load the Raygun see also in this default character or in this old blueprint lecture I added cones to my hand so I can tell which way my hand is facing and that I can do here I have this food so I am doing the same thing basically I'm loading the basic cone into something called cone and then I'm telling both the left and right meshes to use that cone and that will that will load the cones the same way I didn't compile it yet just because I don't want to wait for that to set up the material actually maybe I should compile it just to show you so if I compile this the cones won't have any materials so left cone it'll just be this gray default material I'm actually wanted to use a white material because the default material looks weird so I wanted to use where are they I want to use this white material so to load the material I can basically do the same thing except instead of using static mesh avec use material so here is loading the material and I'm loading this gray material it's he used for this and I have a function that will also set the material inside of a static mesh component so for the left cone and the right mesh set material has two parameters the first is the index of the thing that you're loading material for the reason you have index is because a lot of meshes have multiple material slots like for example if you want to if you have a mirror for example you might have a material for the outer rim like it might be wood and then you have a different material for the inside classy part and those could be two different materials or you can use like reflectance map or something like that anyway these the cone only has one material slot so I just loaded into the slot zero and I load it as great and this will work and if I create some new character you'll see that this will already be great C++ class yay it's this gray material they are too big one thing that's nice though is a VR preview will just work so if I play it it's very unhappy about something right now cap doesn't crush hmm that's very interesting well just keep up are we open it quickly oh it decided to save at the exact same time that he was playing or no this is something different I can't until I have four unreal instants open anyway let's make this a little quickly I just want to sets I just want to set these things on my hand to be right so that we can move on next time unreeled acting lawfully community right now hmm so I'm on you can also play it from here local windows debugger this should load it and it will also tell you if it's crashing while it's loading it doesn't seem to be it's just not doing anything we are working steamvr is working maybe doesn't like that I have other on real projects open I don't know it's no that's very unhappy about something try again all right I guess it was just one of the other unreal must have locked some asset oh man you can't see I don't need these Oh was I trying to show oh yeah I wanted to show in VR that the cones are way too big oh and it's also using the first person character because that's what it's supposed to be using um for this we can just tell it to instead of using the first person character to use mine I'm gonna just make a quick blueprint class for a game mode key mode and tell it to use my player folks on with us and tell it to use this one [Music] okay anyway here in my hands and you can see the cone is gigantic and it's not pointing the right way for the one that was on the gun I actually wanted it to point I wanted it to be at the tip of the gun so that I can have the pointy part of the cone points in the direction that bullet should shoot to make the math easier um the other one should just points where my hand should be but it's not I should won't know where it is I think it's just lost tracking oh oh I know what the problem is the problem is that right now the when it initializes this character it initializes the it initializes both hands to be left because I didn't tell it otherwise so right controller is still right and again we want to change this in C++ because that's kind of the whole point of this and because otherwise otherwise if you tried to change it right here then when you spawn the character the spawn a new character won't have changed so in the constructor we can call some functions that will do this for us they are these functions so you need this class so the motion source is which hand it's coming from or if you have live shockers or anything like that it'll be the ID there's a right hand and a left hand source ID you need to import this where is it XR controller base needs import this to get its actually find these and because I'm running this right now I can't actually build it while it's in I can't build it from Visual Studio because it'll shut the game off so I'll compile it from here instead and if I creates this character again it will now initialize that is rights see cones are still too big and this is actually a blueprint would be useful for even if you don't want to use blueprints a program it's still useful for positioning things which is probably why with the first person character they still have a blueprint of the character even if they're even if all their code is in C++ because as you can see they used it to position things in the viewport they position the arms and other things because it's just heart it C++ doesn't have a visual editor for these things but just for the sake of doing it because we wanted I want to show you how to do all the things in C++ that you would need to do I will do it in C++ just to appease so in the other C++ and the other original blueprint project I already had values that I was using and I can still use those values you know you could imagine how much effort it would be to try to do this manually but I happen to know what these values already so I just put them in for the Raygun and the Cohens I set their locations and their scales to be the right thing so cone should be smaller they were rotated a certain way so that they point forward and the left one specifically I moved to the front of the gun and these are relative because I don't know which way the characters going to be pointing when the game starts anyway let's check hurt I'll play it since I have a game mode that initializes this person for me I have my two controllers I have the left one and you can see the cone is not pointing the right way with these values that I happen to know already and this cone is also pointing the right way now I'm gonna leave off with the just this very last thing so yeah positioning these in C++ accurately is pretty much impossible so what we can do instead is create a blueprint subclass that we use just for the positioning of these things so I can right-click this and say create a blueprint class that extends the C++ class and I'll call it VR BP pond and you can see this is a subclass of this C++ class and I'm working with right now and it has all of these things and yeah they're already initialized because I set them in the constructor but let's say that I didn't let's say that I ain't got heard of these and recompiled they would no longer be in the right place well I already created this subclass um yeah it doesn't matter much yet I already created the subclass when it was positioned in that other way already um so this is do anything but let's say that I did want to position these automatically so let's say that or let's say that I wanted to position these outside of C++ but with the blueprint instead let's say that I want this cone to be in front like this just for now for the sake of example in blueprint obviously I can position this very easily and if I want to now use this blueprint subclass I just tell the game-mode to use that one instead and all of my code is still being done in C++ but I'm just using the blueprint for positioning because it's easier so my game mode now knows that I'm supposed to be using the BP one that has fixed transforms and you can see that it is in fact using the offset cone and it's just too hard to position things in C++ so this is the common way of doing it uh yeah that's gonna be it for now and one of the reasons that I recommend people not do the 590 assignments in C++ is exactly this it took so long just to do the basic setup yeah when you were loading the meshes those things like loaded obj and cone and great mat yeah what exactly would you formally like what are those these are like it's it's just it's basically creating a pointer in C++ to these exact things in the content browser so Raygun is exactly this Raygun okay and you're initializing it there on that line right yeah I need to know I need to load it so that I know what to set as a static mesh because um like you can't just set the static mesh as a name or anything like that you need an actual pointer to an asset that exists okay and the reason it's static is because you know you're loading something that already exists right in the editor you can't just change what a cone is inside of C++ release you're not supposed to so they have you load this statically basically creating a pointer to that exact asset the reason that I knew that this was it this is an engine asset so it's not actually in my game but if I throw a cone in my scene and I look at the static mesh I see that there's a cone here and you can right-click the so you can see the path right here but you can also right-click copy it and paste it here too so you know it'll give you this and you can throw that in there and there actually is no difference between either of these ways of loading it like you can just use the path by itself like this or you can use static mesh whatever this thing that got copied automatically um they both work I don't I don't know this is what it looked this is what it copies automatically so I don't know either one works it just depends on which it just depends on whether or not you happen to copy from the editor or type it out I guess but they do the same thing oh good yeah as I was saying this the basic setup has taken so long and that's why I didn't recommend people do the C++ or the assignments in C++ because if you don't already know how to do things and C++ it just takes so long to do the most basic things the code that we'll do later will be a little bit more manageable but today we just did the setup code which is the least fun part and next time we'll do the the actual VR code that we need so if nobody has any other questions and I'll just hang out I'll close my
Info
Channel: Nick Rewkowski
Views: 1,838
Rating: undefined out of 5
Keywords: ue4, c++, vr, unreal
Id: N7TUC0ZvuGM
Channel Id: undefined
Length: 70min 44sec (4244 seconds)
Published: Mon May 25 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.