In this series of posts, I will be creating a simple Pickup system and Inventory system in Unreal Engine 4. This is targeted to the beginners in Unreal Engine 4 who want to create simple pickup system in game environment which interacts with our character player and adds pickup to the game inventory.
In the very first part, we will create a pickup which we can add to game environment. When our player interacts with this pickup, then pickup is destroyed from environment.
Lets start making our first simple pickup system using following steps.
- First of all create a blueprint class of type Actor. Name this as “Pickup”. Open your newly created Pickup blueprint.
- Add a Static Mesh component into the scene of your Pickup blueprint. This mesh will represent the pickup which you want to add into your game level.
- Also add a Sphere Collision component into the scene. This will be used to detect interaction of pickup with the player character.
- Your pickup blueprint will look like something in screenshot below.
- Now click on Sphere, and go to details Panel. You’ll find “On Component Begin Overlap ” event in Events section of details panel. Click on it and it will open in the Event Graph of your Pickup Blueprint.
- Now on Begin Overlap Event, you need to find out whether the character is overlapping the sphere component and if yes then you can destroy your pickup after adding it to inventory. We will cover the inventory portion in next posts.
What is happening here is , we are checking whether the other actor which is overlapping Sphere component is the Player character. If true, then destroy self. That means destroy pickup from game environment.
- Now next step you need to do is add a static mesh to the component that we defined in second step.
- Play with Sphere settings to change its radius so that the Static mesh for pickup lies inside the Sphere component. It will look something like below :
- Now you can drag your Pickup blueprint and add into your game level by dropping the blueprint into the level.
- You’ll find out that all your pickups are having same Static mesh. What if you want to have different static meshes for different pickups. Go back to your Pickup Blueprint and add a new variable of type Static Mesh to it. Name it “Pickup Mesh To use”. Make this variable public.
- Now every time you add a Pickup into your level, you’ll have an option to select a static mesh in the details panel of the pickup that you’ve added. This is not it, you need to pass this selected mesh to the Static mesh component that we created in second step. We’ll do it using Construction Script in our pickup blueprint. Drag Static Mesh component into your construction script, and drag wire from it to search for “Set Static Mesh”. Pass “Pick Up Mesh To Use” as New mesh to this node. Your construction script will look like following.
- Now you are good to go. You can select a different mesh for each Pickup that you’ll drop into the level.
If we are going to destroy the pickup on interaction with Character then it is obviously of no use. So in our next post , we will add our pickup to the Inventory and will show up our Inventory on pressing I button. So stay tuned for the next post.
Please help me to improve my posts by asking any questions if you are facing any difficulties while following these steps. Thanks for your time. 🙂