🌍 Making an Inventory and a Building System! | Terra Devlog #3 | Unreal Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome back to the Terra devlog a survival and exploration game set on your very own Planet I just want to start this video off by saying thank you all so much for 1,000 subscribers I truly appreciate all your nice and constructive feedback on both the game and the channel so please keep them coming I also told myself that when I passed 1,000 subscribers I would make a Discord server for the channel where we can chat and I can share some progress on Tera in between videos and also answer some questions about the development in better detail than in the comment section here on YouTube so if you want to join an invite link is in the description we're still a very small community of course but I feel like a Discord channel is pretty nice to have anyways so again thanks a lot for 1,000 subscribers and enjoy the video in the last devlog we used the voxel plugin to generate our planet procedurally and Scattered some simple trees all around our world this time I want to add some simple interactivity to our world so that's why I'm going to start implementing three of the core Mechanics for the game first I want to be able to gather resources from the world then I need a way to store these items so we need some kind of inventory system and then third I want to be able to spend these resources in some way these are three very typical Mechanics for a survival game so of course I want them in Terra as well and since our planet is filled with these trees and honestly not much else yet we should probably use them to implement our mechanics so my plan is simply That We Gather Resources by harvesting these trees and picking up logs that they drop and after that we need to be able to place these logs around our world to make structures this covers all our three mechanics and if we Implement them in a clever way it should be easy to extend them to work with all kinds of resources and be easily extendable for the future so let's start this off with step one by making a way to gather resources since we wanton to gather logs from our trees we need a way to chop them down so the first thing I want to do is head over to mixo and find a simple punching animation we don't have axes in the game yet so our poor character will have to punch the trees with his bare hands for now but I'll give him an axx soon I promise and if you don't already know about this page mixo it is a great place to find tons of free animations for your games they might not be the best in the world or fit 100% with your character but they are great for prototyping as you probably don't want to do a lot of custom handmade animations in this stage anyways so after importing our punching animation into unreal I retarget it to fit with the unreal skeleton and voila a very basic punching animation cool now we just need to activate this animation when I click my mouse and a very simple way of doing this is of course to just play the animation Montage when I click the mouse button and this works well if your game is single player however ever in my case I want to make sure that my game works in multiplayer as well and by using this simple solution only the player clicking the mouse will see the animation play on their character no one else will I'll try to explain a bit why this is so when I click my mouse button only my computer knows about this button being clicked right so therefore only my computer will run this mouse clicked event and then start the animation it won't run on anyone else's computer because their computer is obviously don't know about this button being clicked so we need to manually send a message to everyone in the same game as me and tell them that hey I just clicked my button and I'm running this animation Montage now to do this we have something called rpcs in unal engine they look just like regular events except they're designed to help you send these messages to the other clients they're very simple you just make a regular custom event and here in the details panel we can set what type of RPC this event is with this replicates drop down there's one in here that is called multicast if we select this and then call the event it will run this event on all the clients connected to our server so if we hook up our animation to this event instead and then call this event when we click our Mouse button then the animation will be played for all the connected players however still when we try to click on our client we can see that nope it's still does not run the animation for the other player and that is because these multicast events they have to be ran on the server because the server is the only one that can talk to all the clients connected to it so therefore if we want our client to be able to run this multicast event we have to make another RPC this time it will be the run on server RPC because this RPC allows the client to ask the server to do something for it and because the multicast can only be run on the server our client will ask the server to run this multicast for us so the whole functionality works like this when combined I click my mouse button then my game asks the server if it can run the animation on all the connected clients for us and then when done in this way the animation will successfully be played for everyone no matter if you are the one running the server or if you're just a client connected to it so that's a little bit of multiplayer logic and unreel engion for you I hope you found it helpful in some way all right so now we have an animation that is played on all the clients now we just need to check if there's anything in front of us while we play this animation so that we can punch the living crap out of it I did this with a simple animation notify that does a sphere Trace in the direction I'm looking and then this sphere Trace will detect what kind of actor or what kind of component I am punching and as you can see the trace becomes green when it hits the tree so that means that we successfully have the detected this tree now we just need to do something with it and for now the voxal plugin which I'm using to generate these trees have very limited interactivity with foliage basically the only thing I can do with the trees is change the visibility of them but I can work with that for now so I set the visibility of the tree to false if I hit it and now it looks like I am removing trees great this is a bit boring though as we usually would need to put some effort into chopping down the trees and then be rewarded with logs when we manage to break it so at the same time as I make the tree invisible I want to spawn an identical tree blueprint at the same location as the old tree and with this tree blueprint I can do whatever I want like for example give it some health and also make it shake a bit when I hit it and then when the health is zero I will destroy the tree and then I'll spawn a log pickup for the player so he gets his reward so I now have an interactable tree if if I hit it it will shake and lose some health and when the health is zero it'll spawn a log pickup amazing so that is step one finished we now have a way to interact with our foliage to gather resources from it now we need to be able to store this log on our player somewhere currently I can walk over to it and pick it up but in reality this just destroys the pickup and I'm not able to use this log in anyway since I don't have an inventory that lets me interact with my items so that is the next step making a simple inventory system I wanted my inventory system to be its own self-contained component so that I could put it on anything that I want to be able to store items such as chests and workshops but also players and animals this component will simply contain an array of all the items in this inventory and how many there are of each of them and it will also handle all the logic needed for it such as adding and removing items I won't go into detail on how I made it as it is really quite simple at this point but the important takeaway from it is that it is its own component and that it contains the array of items in the inventory now we just need to make all our items so I made a struct that contains some basic information that all items need such as an ID and the name and as the ID of my items I'm going to use something I recently discovered in Unreal Engine called gameplay tags if you don't already know what this is it's used in the same way as regular tags except that these gameplay tags can contain subtags so for example the ID of a sword could be item. weapon. sword and then in my code I can easily tell that this sword is a weapon and also an item I can store in my inventory then I can do some logic based on this information unreal also gives us this handy list of all our tags so we can easily click what tags we want for our item without having to type it in manually every time we want to reference it so that's why I want all my items to have gameplay tags as their ID and now that we have our simple item struct we can make a data table for this struct where we can define a big list of all the items we want to exist in our game for now I'll just add these three test items a sword an Axe and the logs later I will add more data to these items such as what their icon will be in the inventory and their 3D meshes now that we have defined our new items we can go into our pickup class and when something is trying to pick this item up we can try to get their inventory component and if they have a valid inventory component we can use the add item function to add some items to this inventory before it destroys itself okay let's try this out let's cut down a tree pick up the item and then have a look in my players inventory component and yeah I now have five logs great but it would be really nice if we could actually see the logs on our screen as well with some kind of inventory UI so I quickly mocked up a simple inventory slot widget that shows an icon and the amount of this item we have and then just made a row of these inventory thoughts and now would probably also be a good time to add the item icons to the item data stct we made earlier so that we can find this item icon in our inventory UI so I added a new field for a texture and set the icon for the logs to be this nice log texture and while we're here I also added a field for the static mesh as we want to be able to display this in our hand the later in my inventory UI I can now use the inventory component to see what item should be in each of these inventory slots and then set the icon texture and the amount text to their correct values and look at that we can now see all the items we have in our inventory in this hot bar that's a lot better I also made this hot bar scrollable so we can choose what item we want to be active and then based on what item we currently have active I get the mesh of the item from the item data and add this mesh to our hand so it looks like we're holding our currently active item perfect so now we have completed the Second Step storing our items in an inventory and that just leaves us with the last step a way to use our resources and as I mentioned earlier I want to be able to place these logs in the world to make structures so that's what I'm going to work on next the first thing we will do to make our building system is and yeah you probably guessed it make a building system component that contains all our building logic I like to separate my code into components it makes everything way more manageable now that we have our component we're ready to make the functionality we need first we need to know when our character is in build mode and when it's not this will be decided by our currently active item I will put this placeable checkbox in the item data along with everything else and then if it is a placeable item we will enter build mode when this item becomes active and make sure our logs have this check then when we are in build mode we need a visual representation of the item we are placing so we know how it's going to look like when it's placed so I'll do a line Trace in the direction I am looking and make this representation follow where my line Trace hits the ground every tick and then when I click my right Mouse button I want to place my item at the exact same location as my representation and that's basically the core of our building system now I can place these logs anywhere I want oh and look at that I think my character is trying to tell you something currently I can just Place infinitely of these without consequences so let me quickly make sure to remove One log from my inventory each time I place one so that I eventually run out and have to gather more another feature I want to quickly add to my building system is that once we have placed something I want to enter some sort of snapping mode so that the next item we place can be snapped perfectly to our previously placed item so I made a function in my building system component that takes the hit location of our line trace and snap it to a custom grid based on the size of our currently active item here is the function in case you want to have a closer look at it then after I place my first item I make my placement logic use the snapping function so that the next item we place can be perfectly aligned with the previous one if we no longer want it to snap we just switch our active item to something else and then switch back and then we'll no longer be snapping I also made it so if you hover over an item that already exist your placement will automatically start snapping to this item in case you want to snap to something that already is in the world the last thing I did in the building system is to let the player rotate the placement of your item with the r key so this lets the player Place items on an angle I'll experiment a lot with this building system to see what works well and what doesn't it's very simple at its current state but it will of course be expanded upon when I need to improve it even with these simple features and with only logs I managed to make a small house look at this the first structure in Terra this is a big milestone so now we have all our three mechanics implemented we have a way to gather resources we can store items in inventories and we can place our items in the world all of these systems are of course in very early stages and will be approved a lot later but it's very nice to have at least some of these core mechanics in place so we have a base for all our other functionality to build upon all right I'll end this Dev vog here I hope you enjoyed it and also if you want don't forget to join the Discord server with the invite Link in the description if there's anything about Tera you have questions about or have suggestions for stuff then Discord is a great place to do that or just hop in for the chat of course and also make sure to subscribe to the channel so you don't miss the next de Vlogs and if you enjoyed this video a like would bring a big smile to my face thanks a lot catch you later
Info
Channel: Emil
Views: 1,928
Rating: undefined out of 5
Keywords: unreal, devlog, terra, unreal engine, dream, game, development, procedural, voxel, voxel plguin, core mechanics, inventory system, building system, planet, gamedesign, showcase, art, progress, indiedev, gamedev, procedural generation
Id: MYlVkTdFIa4
Channel Id: undefined
Length: 14min 57sec (897 seconds)
Published: Thu May 02 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.