jueves, 8 de octubre de 2015

Item Blueprint Functionality

[This post was done to be taken as Homework 5 for the FSU Video Game Design class]

This post serves as a showcase and description of the main blueprint for in-game items that makes up the inventory system in our game. The following text will consist on a brief overview of the function of the blueprint as well as a more detailed description of its content. To start of let me clear out that I simply applied what I learned from an Unreal Engine Tutorial (link at the end), so I will be explaining it in detail in my own words to proof that I have learned the material and not just simply copied it. I will encourage anyone to look at this tutorial as well as other tutorials offered at Unreal’s Youtube page, they are very comprehensive. With that said let us start with the overview.

The blueprint system that I’m showcasing here is meant to provide the functionality to items in our game. The blueprint spawns a text on top of the item as the player get in range and this text follows the player around as he moves [Image 1]. The blueprint also enables the item to be picked up and stored in the inventory [Image 2]. And finally, it gives functionality to the item as it sets the different status modifiers triggered when it is used. This blueprint is made in such a way so that it serves as a template for all other objects that are going to be in the game. So we won’t have to make mayor alterations to the blueprint to include different items that do different things. Just to make this clear one more time, there are many blueprint that interact with each other to make up the inventory system, we will only get into the blueprint that directly controls the mesh object’s behavior.


Image 1 "It moves!!"


Image 2 "There it is in our inventory!"

Now that we have gotten the main function of the blueprint out of the way let’s talk about the contents. Let’s start with the first event that will run in this blueprint, the “Event BeginPlay” [Image 3]. The “Event BeginPlay” activates when the game starts and right after that the nod “Create Pickup Text Widget” follows, enabling the pickup text widget to appear in the game. This is then stored in a variable called “Pickup Text Reference” so we can change the two different values that affect our pickup text, the item under it and the text that need to be displayed. To do that we need to set the variables in the “Item Info” to the specific ones for each item each item. So we use the nod “Set members in Inventory Struct” to set the elements of the structure “Item Info” to their respective values. To call on these different elements we need to use the nod “Break InventoryStruct” to get the different values that this structure contains. Then we need to set those values to variables that will be then used by the “Pickup Text Reference” to display the right text on top of the right actor. After that we basically create a variable that references our character blueprint called “Character Reference” so we can reference the event in which the player picks up and item called “PickupItem Event”. All of this is done in an effort to make the name that appears on top of the items, as well as the other elements that make it unique, editable so that we don’t have to create a specific blueprint for each item that has a different name in the game.


Image 3 "Event Begin Play"

The second main event that interacts with our Blueprint is the event “PickupItem” [Image 4] which triggers every time we pick up an item. As this event happens a condition has to be met for the Blueprint to go on. The “Branch” nod works as an “if…else” statement that we can set to true if some condition is met. In this case we want this condition to be if player is in range (variable added from next step) and if the collision in the actor is enabled (i.e. if the item is not hidden) then continue the Blueprint, else do nothing. If the blueprint continues then it will add our item to the inventory menu which is in our “Survive HUD”, the UI blueprint. Then we remove the text from the top of the item with the “Remove from Parent” nod, hide the item from the game with the “Set Actor Hidden in Game” node, we use the “Set Actor Enable Collision” to disable the collision and finally we call the function “Refresh Inventory” from our “Survive HUD” which is a blueprint that adjusts our inventory to the new items.


Image 4 "Pickup item and add to inventory"

The events that add and remove the pickup text to the Viewport are the “OnComponentBeginOverlap” and “OnComponentEndOverlap” [Image 5] which are referencing a trigger box around our object. We use the “Cast To MyCharacter” nod so that the event doesn’t fire up when other actors collision with the trigger. Then we simply use the nod “AddToViewport” when “OnComponentBeginOverlap” triggers and “Remove from Parent” when “OnComponentEndOverlap” triggers. We set the target of both of those new nods to the “Pickup Text Reference” so that they remove and add the pickup text from our Viewport. After that we just set the variable “IsinRange” depending if the collision is happening or not so that we can reference is like we did on the previous event.


Image 5 "Pickup text trigger"

This next part of the blueprint is the part that controls the different functions that the item has in the game such as the health and energy it increases. When the event “Use Action” is called, which triggers when the player uses the item, the health, energy and heart rate values of our character get edited. So we get a reference to our character by using on the “Character Reference” variable and then use our variables for “Add Health”, “Add Energy” and “Add Heart Rate” to modify our current status values. We get the current value of all the statuses from the “Character Reference” variable then we add our modifiers and finally we set the max value for our modified statuses to 1 (or 100%) so we don’t go higher than that. After all of this is done we destroy the actor from our game with the nod “Destroy Actor”.


Image 6 "Item Functionality"

The final part of the blueprint is the one that lets us edit our different variables for the item mesh, the item pickup text, the item use text, the health value, energy value and basically all we need to make that item unique. The construction script is fired every time any changes happen with the blueprint. So what we do is that we use the “Set members in InventoryStruct” nod to set the values for the structure called “Item info” which will give the unique values for each item. Doing this in our construction script lets us access this variables from the details panel, which saves us a ton of time when working with a lot of items.


Image 7 "Construction Script"

So that is it for this description. Keep in mind that I’m not an expert so I may have missed something. Also this is a work in progress and I still need to work out a few bugs. And finally remember that this a component of the set that form our inventory system so you might not be able to create this same item with the images and descriptions that I have provided. Please if you want to do this successfully then refer to the link at the end for the post.


No hay comentarios:

Publicar un comentario