How can pick up an item when touching it?

I want to be able to pick up a ball when I touch it. I want my player to hold it under their arm. How can i script it using blueprint

You’ll want to give the ball a sphere collider. Make sure it’s large enough:

Add a begin overlap event to that collider:

We then just check whether that overlapped actor was actually the player.


If it was, we call an event you have to create in the player.

To create this event, we just create an event with a parameter of the ball’s type (for me it’s BallPickup).


In the event, we see if a variable we create to reference our held ball is valid. If it isn’t, that means we aren’t holding anything. We then set the reference to indicate we are now holding something, disable that something’s collision so we don’t get flung around, and attach that actor to a scene component we’ve placed in our player to decide where we hold the ball.

My attach point:

Result:

Thank You for this, Can you explain the fourth step in a bit more detail, I do not know how to attach the actor to a scene component and I do not understand past the script in the actor fo the ball

The BallOverlapped event in the player? Sure.

  1. We have a variable that stores a reference to our currently held ball.
    image
    This is for checking whether we are currently holding a ball- we also need a reference for when we throw it or otherwise want to detach it from the player.

  2. We also have a scene component. The purpose of this is to determine where the ball will go.
    Simply put, this just stores a location. In my example, I have it positioned in front of the player to make it clear, but you can put it wherever.

  3. The event is called from your ball, which passes itself as a reference. This is so the player knows which ball was overlapped.
    image

  4. This first branch node simply gets a reference to our currently held ball pickup, and checks if it is invalid. If it’s valid, that means we’re holding something, but if it’s invalid, that means we’re not. We’re making sure that we’re not already holding a ball.

  5. Here we’re updating our CurrentlyHeldBallPickup variable since we are now actually holding something. We are now holding this ball, so we set the variable to indicate as such.
    image

  6. Next we disable the collision of the ball pickup. If you don’t, the player and ball will collide and uncontrollably fly around the map.
    image

  7. Finally, we attach the ball to our scene component. This will cause the ball to move along with the player.
    The target (CurrentHeldBallPickup) is the child we’re attaching to a parent (Ball Attach Point, our scene component).
    The location, rotation, and scale rules are all set to just move to our scene component.
    If you didn’t use these settings, the ball would either keep its relative location to the player when first picked up, or wouldn’t move at all.