Make any actor grabbable¶
By the end of this page, players can pick up your actor with the left mouse button, carry it with physics and drop it again, the same way they carry loot. You need one physics mesh, a few settings, and the BPI_Grabbable interface. You do not need to change the player.
If you have not read How grabbing works, and tuning the weight, start there.
- The interface:
Content/MPFriendslop/Blueprints/Interfaces/BPI_Grabbable - The ready-made loot:
Blueprints/Environments/Loot/BP_LootBaseand its children inBlueprints/Environments/Loot/Childs/
The quick way: a child of the loot base¶
If your object is loot, do not build it from scratch. Duplicate the BP_Loot_* child closest to yours, or make a new child of BP_LootBase.
- Set the
Static MeshonMesh. - On
Mesh, in the Physics section, type the weight inMass (kg). The override is already ticked onBP_LootBase. - Fill
Loot Dataon itsBP_LootValueComponent.
BP_LootBase already implements BPI_Grabbable and has every setting from the next section. A child sets only its mesh, its mass and its loot data. The loot side is covered in Add a loot item.
Your own actor¶
Use this when the object is not loot: a prop, a key part, a body. BP_PlayerHead in Blueprints/PlayerCharacter/ is the example that ships: it is grabbable without being a child of BP_LootBase.
- Make a Blueprint with parent
Actor. Put your Static Mesh component at the root. - On the mesh, tick
Simulate Physics. - In the Physics section, tick the override next to
Mass (kg)and set the weight. - In Collision, set a
Customprofile withCollision EnabledonQuery and Physics, object typePhysicsBody,VisibilityonBlockandPawnonIgnore. - Still in Collision, set
Can Character Step Up OntoNoand tickUse CCD. - In the actor's Class Defaults, under Replication, tick
ReplicatesandReplicate Movement, and setPhysics Replication ModetoPredictive Interpolation. - In Class Settings, add
BPI_Grabbableto Implemented Interfaces. - Add a variable
Current Holderof typeActor, set toReplicated. - Fill in the interface functions from the table below.
That copies the collision of BP_LootBase. Pawn on Ignore is what lets players walk through the object instead of kicking it or standing on it.
The interface functions¶
| Function | What to return or do | If you leave it empty |
|---|---|---|
CanGrab |
true when nobody holds the object, or when Grabber is already the holder. BP_PlayerHead also refuses once the head sits in a revive bay. |
Returns false: nobody can ever grab it. |
GetGrabMode |
Free, for a physics carry. |
Returns Free, which is what you want. |
Grab |
Set Current Holder to Grabber. |
Nothing remembers who holds it. |
Release |
If Current Holder is Grabber, clear it. |
The holder never clears. |
GetGrabHolder |
Return Current Holder. |
Returns nothing. A melee weapon never finds who swings it, so it deals no damage. |
GetGrabUpright |
Align Upright true, an Upright Offset and a Max Lean Angle, when the object must stay upright in the hand. BP_LootBase returns its own three fields of the same names. |
The object keeps the angle it had when you grabbed it. |
GetGrabMotionComponent |
Nothing. | The mesh you grabbed is used. |
UpdateGrabAim is only for the Axis mode of levers and drawers, covered in Make your own door, switch or lever.
The settings that break it¶
| Setting | Where | If it is wrong |
|---|---|---|
Simulate Physics |
the mesh | The server refuses the grab. |
Visibility on Block |
the mesh collision | The player's trace never sees the object: no open hand, no grab. |
Replicates |
the actor | What the server does to the object never reaches the clients. |
Physics Replication Mode |
the actor | Clients see the object stutter. |
CanGrab |
the interface | Left empty, it answers false. |
Warning
Physics Replication Mode is not set for you by the grab component. BP_LootBase and BP_PlayerHead set it to Predictive Interpolation. Your own actor keeps the engine default until you change it, and nothing in the log tells you.
To turn your new grabbable into a weapon, see Turn any grabbable object into a melee weapon.