Hello and Happy New year
I would like to learn how to Pickup and place items on a lock/ when all have been placed an event is trigger.
In this image there lock requires 3 items.
The player would pickup and item (Scorpion disc) attach to hand-r take to the lock and detach actor.
When all 3 are in place, an event is activated.
Can someone please help me with an overview or maybe a blueprint screenshot?
Thank you for any help
video games are full of lies, and in many cases it is trying to be honest that makes things like this harder. at the same time âGame Development is hardâ not because any given thing is hard (some of them are, but most are not), but rather because every little âsmallâ decision you think you are making actually has 20-30 knock-on decisions that need to be make almost immediately, and it comes down to which of these are you going to ignore, mitigate, or embrace. (you can look into âThe Door Problemâ, âThe Latter Problemâ, or âThe Stairs Problemâ which are really just illustrations of this)
lets first look at the item to be picked up; we need some way to know that we can âpick it upâ this can be in a few ways, and each one comes with assumptions/questions:
- will the item go through load zones?
- will the item be throwable, or react to physics while it is âbeing heldâ?
- can there be multiple items held?
for the switch;
- can the wrong object be placed in the wrong spot?
- can a completely different object be placed in a given spot?
-
- can the player pick up a chicken, and put it in/on one of the slots?
- must the objects be placed in a specific order?
-
- if they put the snake down before the scorpion does a giant Scorpion come and attack them, does the puzzle need to be reset?
- is the switch responsible for orienting, and âplacingâ an object on it?
-
- if there is only ever the one object that can be placed there then maybe âthe object was there the whole timeâ it just needed to be interacted with the correct key to be materialize.
this is a âsimpleâ process that will make a deal of assumptions to these questions:
if an item that can be picked up is inherited from a given âpickupâ or a more broad âInteractableâ class (a pickup could inherit from the interactable even) then when you trigger the interaction check for the class. where the âpickupâ or âinteractableâ has an identifier that it is a keyItem, and some identifier for what it specifically is, or does (this doesnât NEED to be a specific subclass, but just like an integer ID)
if the object is not inheriting from either a âpickupâ or âinteractableâ then you can use tags to figure out what they are (these are runtime resolved based on exact strings, and it is acceptable for the compares to silently fail because a capitalization, or spelling difference)
instead of âactually picking it upâ we can fake this. the reasons to avoid doing the real thing:
- when you attach an item as a child object it now needs to have bookkeeping performed (mainly that you will need to be applying the resultant transform where primarily scale, and rotation can easily be an issue when detaching it)
if the object must go through load transitions then you can still attach it, but attach it to the pawnâs root.
if we give pawn a StaticMeshComponent RightHandSlot that we intentionally donât assign anything to, then wen we âpick upâ the object:
- get a pointer to the original object and assign it to a member variable (HeldObjectRightHand)
- get the StaticMesh of the object being âpicked upâ
- place that StaticMesh as the RightHandSlot StaticMesh
- with the HeldObjectRightHand change its collision response to âNo Collisionâ, and change âHidden in Gameâ to true. (the object now has no collision, and will be ignored on the next render pass)
- be sure that the RightHandSlot at the very least has its âHidden in Gameâ set to false.
now the pawn is âholding the itemâ
to âput it downâ
- check that the spot is valid for it to be placed (this goes back to those question earlier)
- if a variety of objects can be placed in a given spot (the player tries to put the Snake on the Scorpion) then:
-
- take that pointer to the HeldObjectRightHand, teleport it to the place it will be placed (if you attached it, then detach it now)
-
- enable the renderer of HeldObjectRightHand (change âHidden in Gameâ to false)
-
- if the object can be picked up again then re-enable the collision ( change the collision response to at least âquery onlyâ but if you need physics then do all that as well)
-
- for the RightHand slot: either disable the renderer; then set its StaticMesh to None, or just set its StaticMesh to None, really up to you and will have the same result.
- then set the HeldObjectRightHand to None
if the object is meant to have physics or it is a SkeletalMesh while being held things get a lot more tricky, and will probably require actually dealing with the book keeping of actually attaching it in the location, and later detaching it.
3 Likes
Thatâs an awesome overview. Thank you 