Making my first game in Unreal Engine: Part 4 - Equipping Instruments
23rd August 2022
This blog post is part of a series of blog posts about Bard Game!
In my previous blog post, I talked about how I implemented an inventory system in Bard Game - it’s come a long way since then and undergone multiple changes and iterations.
A major feature I wanted to add was the ability for the Bard to equip different instruments and play them.
To achieve this, I had to break down the process (thinking about it all at once was beginning to overwhelm me).
23rd August 2022
This blog post is part of a series of blog posts about Bard Game!
In my previous blog post, I talked about how I implemented an inventory system in Bard Game - it’s come a long way since then and undergone multiple changes and iterations.
A major feature I wanted to add was the ability for the Bard to equip different instruments and play them.
To achieve this, I had to break down the process (thinking about it all at once was beginning to overwhelm me).
Playlist of all Bard Game demos
Breakdown:
Check if Bard has an
︎︎︎
If
︎︎︎ This can be handled from the inventory window
This required an
The fun part was figuring out what to do if Bard already had an instrument equipped:
If the
If
Simple!
Check if Bard has an
EquippedInstrument
upon left click︎︎︎
If
True
, play EquippedInstrument
. If False
, do nothing!
︎︎︎ This can be handled from the inventory window
This required an
UnequipItem
and an EquipItem
function which comprised of either clearing Bard’s EquippedInstrument
variable or setting it respectively.The fun part was figuring out what to do if Bard already had an instrument equipped:
If the
ItemName
of the currently equipped instrument == ItemName
of the instrument Bard is trying to equip, do nothing.If
ItemName
!= ItemName
of the instrument attempting to be equipped, unequip the previous instrument and equip the new one.Simple!
Blueprint showing the EquipItem function
Drag & drop
At this point, equipping and unequipping was performed in the inventory window by clicking on buttons. It worked fine but wasn’t very pretty to look at.
My friend, Chad (who co-founded Bard Game with me) suggested making it so that dragging and dropping an instrument onto Bard would equip it rather than fiddling about clicking buttons.
I knew it would be difficult so I put it off for as long as I could but in my heart, I knew he was right so I began researching how to conduct drag and drop operations inside UE5.
It was very complicated and unintuitive but I got there in the end. These pages of the UE documentation helped out a lot as well as this tutorial by Reid’s Channel.
At this point, equipping and unequipping was performed in the inventory window by clicking on buttons. It worked fine but wasn’t very pretty to look at.
My friend, Chad (who co-founded Bard Game with me) suggested making it so that dragging and dropping an instrument onto Bard would equip it rather than fiddling about clicking buttons.
I knew it would be difficult so I put it off for as long as I could but in my heart, I knew he was right so I began researching how to conduct drag and drop operations inside UE5.
It was very complicated and unintuitive but I got there in the end. These pages of the UE documentation helped out a lot as well as this tutorial by Reid’s Channel.
Demo of equipping instruments - button based
Adding polish
Only instruments can be equipped so when the player attempts to drag an instrument, Bard is highlighted - attempting to drag another kind of item does nothing.
We then get Bard’s location in relation to the camera by drawing a line from the camera to the world (called a Line Trace). If the line hits Bard and we “drop” the instrument, it runs the
For an extra level of fun, we also made it so that Bard’s head follows the cursor while in the inventory - wow!
Only instruments can be equipped so when the player attempts to drag an instrument, Bard is highlighted - attempting to drag another kind of item does nothing.
We then get Bard’s location in relation to the camera by drawing a line from the camera to the world (called a Line Trace). If the line hits Bard and we “drop” the instrument, it runs the
EquipItem
function.For an extra level of fun, we also made it so that Bard’s head follows the cursor while in the inventory - wow!
Demo of equipping instruments - now with drag and drop
After A LOT of work and some final tweaking of bones to make the Lute fit Bard’s hands a bit more appropriately, the system was done! Now we just need to add more instruments, record some tasty jams and make some custom animations to support instruments that aren’t Lutes. Very exciting!
Thanks for taking the time to read this blog post and maybe even watch some of the demo videos!
Take it easy,
Andy
If you require 3D modelling services or you if you just want to talk about 3D modelling, feel free to get in touch with me here or on LinkedIn!
Thanks for taking the time to read this blog post and maybe even watch some of the demo videos!
Take it easy,
Andy
If you require 3D modelling services or you if you just want to talk about 3D modelling, feel free to get in touch with me here or on LinkedIn!