Hi, im pretty new and was wanting to create an interaction similar to how New World has little white circles pop up on the screen when a player walks close enough to something that is harvestable. I also need the widget only to show up for the player that is close enough and not all players, when only one player is close
You can make an overlapping event that toogle the widget visibility, it’s the easiest that comes to mind.
One way would be to create an interface that all harvestable actors implement, call it something like IInteractable. Then have the player’s pawn do a sphere collision trace OnTick and filter to only return the closest actor implementing IInteractable.
Add two variables to the pawn, one to store the widget instance reference and one to store the interactable actor reference. If the widget needs to be shown and does not exist then create the widget and assign the reference to the widget variable. If there are no harvestables and the widget exists then destroy it and clear out the widget variable. Do the same thing to keep track of the interactable actor, assigning it to the closest hit when it is within range and clearing it out when no harvestable actors are in range.
Add a function to IInteractable interface called GetInteractText. Make GetInteractText return a string that contains the text to show in the widget. Use the interactable actor’s screen location to help position the widget.
Add a function to IInteractable called Interact and give it an input parameter of your pawn class. This way you are setup to handle the interaction event later.