Return an object to a specific location - BP Instance variable & tracing

Hello people,

I have a blueprint that I can place in the world, chose the mesh and it become an interactable object that you can inspect, carry with you, throw, etc.
I’d like to have the possibility to return that object to its original location.

So I created a “decoy sphere” on the original location of the object upon picking it up. I’m using a LineTracing on the visibility channel that will detect that sphere to trigger the return.

So the logic here is that when the tracing (from the player’s BP) hit the return sphere, it will change the Object’s BP boolean variable “Return Object” to TRUE. Everything’s work great so far.

The thing is that I am not able to turn it to FALSE when the tracing is not hitting the actor.

Here’s a capture of the situation:

I think the problem is that everything is related to the “Hit Actor”, so that’s why it works when the Tracing hit the object instance. For when it’s not hit? I really don’t know how to point to the specific instance to update the boolean to FALSE. If I create a public variable with a reference to the object’s BP, it seems to trigger the variable on another instance that does not exist and not that specific one.

I’m pretty new to these logics, so maybe there’s a better way to achieve the same result.

Let me know if that’s not clear,
Thanks!

Why do you need a bool? When not just return the object to it’s original location?

Thanks for the reply!
In my Object’s blueprint, I’m using the bool to branch between “returning the object to it’s initial location” and “throw the object”. Left click should do both. Do you think there could be a better solution?

I don’t quite get your logic, but why not just store the original location on begin play?

That way, at any point, you can return it without having to set / unset bools.

1 Like

That’s already done that way and working. I tested with a custom keyboard key and the object is correctly returning to it’s position.

What’s not working is that I’m trying to make it return only when you’re looking toward it’s original location. When the object is carried and the player Left click, the logic should be like “Is the player looking toward the initial location?; TRUE: Return the object; FALSE: Throw the object”.

You seem to be a bit lost in how all that should work, in cases like that i split my big problem into smaller ones, and keep spiting them until i either know how to solve tiny ytask, or know where to look/ask for solution.

In thins case you have two simple tasks mixed together solve one then solve another, and combine them:

  1. first task is remembering original location for actor at being play and returning there upon some event called.
  • so at begin play store either whole TRANSFORM or just actor world location in variable.
  • create event that moves actor back to stored location
  1. second is some logic when item should return and when not when that returning event is triggered
    instead of tracing sphere and all that stuff. You can do some code inside pickup actor that calculates its distance to origin (where it spawned), then you can line trace from camera to that origin and compare traced line length with distance, or check if line trace hit anything.

And last, write here exect conditions for returning dropping it etc. Do not describe it, but write recipe and list of possible states (actions) and when they can happen.

ps. for states or actions, create enumerator and use them easier to read code this way, when you return to that part in few months or years.

Yes, so, if I’m holding it and click: Do a line trace and see if it’s near to the original location. If so, then return it.

Thanks Nawrot & ClockworkOcean, yes I am lost & confused in all this lol. I already did the first task. I wasn’t in the right path by using booleans and the Line Tracing from another actor.

So here’s what I did:
First, I needed to set the original location and rotation of the object. The player’s camera reference also needed to be set here:

Then when using the item in hand, it needs to check if the player is looking toward the initial location. If it is hit by the Line Tracing, return the object to it’s initial location. Otherwise, the item will be thrown.

This is now where the magic happens and where I got confused. I needed to do a LineTrace to check if the player was looking toward the initial location. To be sure the player is looking at the right spot, I used the function “A ==B” with an error tolerance.

And voilà. As I was writing this and making my captures, I simplified a lot the task. Turned out to be pretty simple straightforward. I was getting way out of the path with complicated stuff.

Here’s the result:
test

Thanks a lot!

3 Likes

Nice :smiley: