I watched a basic tutorial on selecting actors on youtube. But my problem now is, that with this code you click an actor to select it and have to click it again to unselect. But in my game it would be beneficial if every other actor would unselect automaticly if you click an actor. For example: I have a tree and a stone so if I click the tree it schould be selected and if I click the stone the stone should be selected and the tree unselected without having to click the tree again.
I attached my code and my question is, is there any way to do this with my code or do I have to do it on another way?
P.s. the code is writtenn in an Actor Component that is attached to the trees and stones
It seems you only want one thing selected. If so, you don’t need to save “isClicked” for each actor.
Create a variable on your player to store the selected actor and a function that first checks if that variable is valid and then calls ToggleSelection on it, then sets the variable to the new object.
From ToggleSelection, if it is a click, get the player and call that function.
You would get a reference to the actor in whatever way is appropriate, then you might need to cast it to the relevant type, then you can just set the variable.