[SOLVED] Help Me With: Dynamic Changed Trace Length

I am building an interaction component and would like to know if it is possible to change the length of the line trace needed to interact with an object in an instanced based manner. Meaning, Object A can be interacted with at 5m (original length) but Object B has to be within 3m (new length), with the original length reset back to 5m when not needing or wanting to interact with Object B. Object A may be a big Actor and Object B may be a smaller Actor.

EXAMPLE:
Base trace length is 1000.0f, with interaction range 500.0f and I have a function to set a new interaction range.
Inside another script or in BP, if new trace length is set on begin play, it overrides it for EVERY actor looked at and not just the one trying to be interacted with.

It wouldn’t make sense to update the length when we look at the object because, if the trace length to the object is less than the original, a new length is set, thus telling the component, we are not looking at the object anymore, and resets back to original length. But the pawn would still looking at the object with a trace length less than the original, setting back to new, creating a loop.

If there is not a known way, I’ll just omit changing the length of the trace.

What I’ve done for a project is that instead of changing the player’s “interact distance”, I used an overly big fixed length for the trace, and when an interactable object is hit I compared the distance between the interactable object and source of the trace (so basically, the player). If the distance is less then the interactable object’s “interact distance” property, then we have a valid interaction.

1 Like

Lol, I overly complicate things as usual. I did that and for the most part it works, just need to clean up logic.

Thank You!

1 Like