Targeting in Multiplayer

Hey, Hope you all are doing great.
Suppose we have two AI(Actors) child classes on of one same parent class. In multiplayer mode how are we supposed to tell them not to attack each other but the other player’s AI Actors since all are deriving from the same parent what am I supposed to cast on in order to find the AI of the other connected players?

Hi @Adeel_Yaqoob

How are you “attaching” them to your players?

Im guessing maybe there is a link to the current players controller?
Or maybe assign them a team number or name that you set a variable in the blueprint to store then they just ignore their own?

Stewart

1 Like

Hi there, I’m moving those characters using a player controller. They are being ordered to act from the player controller. I haven’t assigned any Team name or anything. Just wanted to know how two characters from the same parent can tell if the other one is not friendly and is from another client.

So maybe store the players controller id in the actor blueprint, then do a simple integer compare when targeting , if the id check = your id do nothing, otherwise go kick some ■■■!

Hope this helps

Okay Alright, Is this an optimal solution? Do other games do so?

its A solution, it makes sense , if you want something more advanced then sure theres other ways i guess. but i see no problem with this approach, nor would it cause optimisation issues, just add the playercontroller id in the begin play to your blueprint actors, then its there til you destroy the actor.

Simple and works

1 Like

So if I assign my PlayerController an ID of “1”, how it is going to change the ID on the client side? The client will also have “1”.

Do not assign an ID number instead use -1, this will get the server to allocate the next available player id and then each should be unique

Here take a look at this i just found:

Get Controller ID - Programming & Scripting / Multiplayer & Networking - Epic Developer Community Forums (unrealengine.com)

1 Like

Thanks, Will look into it.