Hi! In my online game i’ve started creating ai enemies. All works fine on server but on client it seems they can’t see client player. Do you have some tips?
can you show your perception logic?
That’s the AI Controller logic when receive a stimuli. It works only if the player is the server. While, if client, enemies block. It seems that they know there is something near but they do nothing.
Only enemy char is replicated. Should I replicate also the AI Controller? I don’t think so
No, AI controller only exist on the server, so you cannot replicate them, its server only.
In your image you only set “FindPlayer?” as a blackboard variable, how does your behavior tree know about the player pawn? Or in other words, LastPlayerSeen is just a variable inside your AI controller, how does the behavior tree know about it?
By the way (most likely not causing your issue, but may lead to unexpected behavior), OnTargetPerceptionUpdated executes when it gets some successfully sensed stimulus (e. g. starts seeing something) or lost some perception (e. g. stops seeing something). In both cases you set LastPlayerSeen, so even if it stops seeing that actor, you set LastPlayerSeen to be that actor. So to differentiate between those two you can check SuccessfullySensed.
If you make use of SuccessfullySensed then instead of using the Tick, you can set a sight radius (e. g. 6000 like in your image) and instead of the “InvisibilityActive” check you can let your pawn ignore the VisibilityCollision Channel. Since AI perception sight uses VisibilityCollision Channel by default once your pawn no longer blocks that channel it can no longer be seen and you will also get an update with SuccessfullySensed being false.
Thanks for the support man.
Ok for the TickEvent, I could change the stimuli of the player from ON to OFF and viceversa when it needs, avoiding the the TickLogic for invisibility.
By the way, all the rest of you answer is not useful. I mean, the LasrPlayerSeen variable is not used in the Behaviour Tree, but just on the AI Controller BP in order to check the invisibility or distance from the enemy. And I make note you that when the condition is false, the LastPlayerSeen is set EMPTY.
I wanna say you that I also tried the logic using the check “SuccessfullySensed”, but nothing changed. So in other words, the problem is not that logic, but it the online AI system of sure.
I read about making run the AI Tree on server with own RPC because client isn’t able to set the BlackBoard variables. Do you know a debug function to see if variables on BB changes on client?
EDIT: The enemy set TRUE when Client is near. But it stops and doesn’t move. In me AI TREE, when PlayerFind? is TRUE, ai use SimpleMoveToLocation:
I saw this code on a famous video about AI on YT. But how does exactly know about the player location?? In my opinion is here the problem, this logic isn’t able to assign a right value tu TargetPlayer (which is the location of the player find ). But on server it works, on client not
EDIT 2: problem found! The location of the player found does not change when client player is near
AI controller and therefore behavior tree and blackboard only exist on the server, they do not exist on clients.
But how does exactly know about the player location?
It doesn’t. It uses the location of the AI pawn and grabs a random navigable location inside a radius of 1500 cm of that location and sets “Vector” with that value.
The location of the player found is always the one of the server! It does not matter of client player… I should work on it
Good that you found the problem =)
You could set LastPlayerSeen also inside your blackboard and then make use of that.
Yeah, I was thinking about that. I let you know
Yeah, setting an Actor variable in BB I’m able to save the player the enemy has seen. So it can automatically know its location. All works fine