I have my HUD Blueprint currently set up so that when one Blueprint actor is targeted and within range it changes the Crosshair into a Hand.
Currently it is only able to do one Blueprint actor at a time unless I rig some really janky Equal To with the boolean combined using a Not Equal To node.
This is only really going to be used as an architectural walkthrough so I’m not to worried with the resource impact but I would like to know the proper way to do this anyway.
I want to know if there is a way to make a whitelist of which BP actors I want the Line Trace by Channel to be affected by.
I am very new to Unreal 4 and any help would be very much appreciated.
I will create a new BP class extended from ‘Actor’ named InteractiveActor. Then for each Actor that you will be able to interact wit, I will extend from this class. I will also attach a sphere volume (or capsule) with it (radius = interaction distance).
Now I will create MyCharacter BP (extended from Pawn/Character). It will have an array of type ‘InteractiveActor’ named ‘ActorsInRange’. Then create an event for ‘OnBeginOverlap’ and ‘OnEndOverlap’ each. In the beginOverlap event, I will check if the overlapped actor is of type InteractiveActor, if yes, I will add it to the ActorInrange array. Conversely, in the EndOverlapEvent, I will remove the Actor from the list
Now you have a list of all the InteractiveActor that are in range of your character.
Within the HUD, you can now get a reference to your character, get the array ‘ActorsInRange’. NOw do a for each loop over the items For each item, do a line trace along the View forward vector (trace length = interaction distance). If it hits, that means you can show the ‘Hand’ icon.
If none of of the items in the array resulted in a successful trace, then show the cross hair.
Optimization: Before doing the trace, you can check if the actor is behind you by doing a Vector subtraction, if yes, then you dont need to do a trace)