Download

Select Actor Client Side

Hello all,

How do you select and actor / unselect an actor the correct way on the client side using a mouse with a channel trace ?
I have been playing around and can get it to work but not fully the client thinks the selected unit is not valid?? I have attached so pics help please




Bump

I see that you’re using a client event inside the unit blueprint, that will not work, you cannot execute client events on an actor that you do not own, I suggest you run the client event inside the character and pass the reference of the unit in the event, make sure the unit has replicate set to true.

Objects you own are for example your player controller, your controlled character, and any blueprint that you manually call the SetOwner function.

Indeed you want the server to make the selection.

You don’t have to have the server make the selection – “selection” is often a client-side concept, and only the “command” that comes out of the “selection” is what needs to go to the server. (This is super common in RTS games, for example.)

I second what @Kaidoom15 is saying: UI interaction should go in the PlayerController. (I don’t like the way that the getting-started samples put a bunch of movement input logic into the characters instead of the player controller, btw – I always end up removing that from the Character and putting it in the PlayerController.)

So, when the user clicks something, your player controller will detect this, and will set some local UI/game state. The rendering for the selectable objects then need to look at local game state to see whether there’s an object that’s selected, and if so, if that’s the current-object, and if so, render it differently. You can update this in Tick(), or you can dig through the object being selected and poke at its material properties from the PlayerController itself, or do it in many other ways, depending on your specific goals.

Note that the “character/pawn” runs on each client, but input only runs on the owner, and the pawn Controller may be different (a replication controller) on the client than on the server.

You’re talking about a case where selecting something is only relevant to the local player, however you can see that OP has a YourTurn boolean variable replicated which could indicate that everyone needs to see what a certain player has selected, in that case it makes sense that the server would transmit such information to everyone involved.

Adding movement inputs to the controller is not bad however personally I find it better to have them on the pawn because the controller could potentially control multiple pawns that could have different input requirements and settings, and as such adding movement inputs in the pawn means you can customize those inputs specifically to that pawn.