I would like to click on an object with the mouse and then return it to its original position by clicking on the object again. I managed to click on the object with the help of a tutorial on YouTube. But I don’t know how to return it. I use the frist person level.
First, I created two Custom Events, GrabItem and DropItem, for cleanliness: I prefer keeping the logic separated, though you can do it without custom events if you want.Then I created a boolean variable IsGrabbingItem. At the end of GrabItem I set it to true, and in DropItem I set it to false.
In DropItem, the first step is to empty the hand: I call Set Static Mesh on the hand component and assign None to New Mesh so the item stops rendering in first person. Then I compute the drop position by taking the Get World Location of the hand/camera and adding the Get Actor Forward Vector multiplied by a distance; that makes it appear a bit in front of the character. With that vector I call SpawnActor and, in Class, I set BP_ITEM to create the actor in the world.
Finally, when E is pressed, I use a Branch with the boolean: if it’s true, I call DropItem; if it’s false, I call GrabItem.
With Custom Events
That should do it. For extra realism, in BP_ITEM I enable physics on the Static Mesh so it doesn’t stay rigid when dropped; and I place the Sphere Collision inside the Static Mesh, attached to it
Sorry, I made a mistake because I misread the statement. Here’s how to do what you were looking for. In the spawn actor, create a new variable of the vector type and set it to the location where you want the item to spawn.