Select/Unselect actor by mouseclick

Hello,

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

When you click on something, save a reference to it in a variable. Then when you click on something else, unclick whatever is in the variable.

1 Like

Thats what I tried before but how can I unclick or set it unclicked for a certain variable? Thats the point I get stuck

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.

1 Like

I will try it tomorrow, thank you!

But just to know it, is there any way to change the IsClicked variable for a certain actor in this BP or another way?

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.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.