First Person Exploration Kit: Creating a Pickup


Pickups are objects that the player can be picked up, carried around, examined, and dropped or put back. Below are the simple steps required to create a brand new Pickup type object in your game.

Pickup

  1. Drag any 3D object into the scene (e.g. model of a coffee mug).
  2. Ensure the Collider is either correctly scaled and rotated (e.g. if using imported Mesh Collider), or remove it completely.
  3. Add a RigidBody
  4. If Collider was removed in step 2, add a new collider (e.g. Box Collider)
  5. Size the Collider (either imported, or added in step 4 above - e.g. Box Collider) to fit for the object you're making.
  6. Run the scene, and see how the physics behave. Sometimes collider bounds don't quite match geometry. Adjust as needed.
  7. Set the Layer of the object to be FPEPickupObjects
  8. Add FPEInteractablePickupScript to your object (this will also add an AudioSource), and set the following variables to suit your object:
  9. Interaction String: For example "Grab Coffee Mug"
  10. Put Back String: For example "Set down Coffee Mug"
  11. If the object's "home" location is the same as its start location, Check "Auto Generate Put Back Object".

  12. Note: that sometimes this can behave oddly if imported Mesh Collider geometry orientation differs fron Unity's coordinate system orientation. If that's the case, either adjust mesh collider, or switch to a Box or other native Collider.

  13. Set Rotation Type, Examination offsets, etc. as required. Sometimes play testing helps judge the best values for oddly shaped objects.
  14. If Enable Sounds is checked, assign sounds if you wish. If no sounds are assigned, generic sounds will be used. This is fine for most small objects.
  15. Run the scene, and interact with your new Pickup object.
  16. To ensure your new pickup can be saved and loaded, you must place it in a Resources folder under the sub folder "Pickups". If you are not going to use game saving and loading in your game, ignore this step.

Optional Optimization: If you know your new pickup object will NEVER use sound, you can uncheck "Enable Sounds" and also Remove the Audio Source component from the Game Object. This is generally not recommended, unless perhaps you are making a Marshmallow object that can only touch other marshmallows :)

Note: There are many things you can create with this object type. For an example of something pretty complex and fun, see demoArtifactPickupObject prefab (or complete "find the artifact" in the demo scene). You can hook up the "Pick up and Put Back Events" of a Pickup type object to any arbitrary scripts or other objects that you wish.

Put Back (Manually Placed)

Sometimes it is necessary to have the put back location for an object be in a different location than its starting location (See demoArtifactPickupObject and demoCardboardBoxSpecial in demo scene). These are also optimal for complex or small meshes (see demoPencil in demo scene), as it can provide a large target for the player, and can prevent "pixel hunting".

Here are the steps to create a manually placed Put Back location:

  1. Add an empty Game Object to the scene
  2. Add Collider type of your choice and size accordingly (Box Collider recommended)
  3. Add FPEPutBackScript to the object
  4. In the Inspector, assign Scene object to My Pickup Object variable for the associated object you want to be put back in this location
  5. Run the scene and test it out. If your object is rotated weirdly when put back, ensure that the Put Back object has the same rotation as its assigned "My Pickup Object".
Note: The transform of the Put Back object will guide the Pickup object when it is put back. So, for example, you could rotate the put back transform and when the pickup object is put back it will assume that rotation as well. It is recommended that the transform's location by slightly above any physics objects to prevent physics clipping and odd reactions when the object is put back. This will prevent physics problems, and also nicely simulate the object being set down from the player's hand.