Client update AI variable on server

Hello, I thought I got the hang of the replication thing, but this one has me confused. I have an AI character BP (Demon_BP). It has a variable called “Level” (Which is an integer that is replicated and instance editable)

When the players do something, I would like to increment the variable Level by 1. (for testing I have it set to pressing the Z key")

The issues is when the client tries to call “Client increase level” nothing happens. I am reading this might be because the client does not “own” the Demon character BP, but I don’t know how I am supposed to achieve this otherwise.

I am not against storing the AI’s level somewhere else, but can’t find a place that works as the client can’t seem to ever tell the server to update the variable for everyone.

Thank you for your input!

Hello,

Thank you for you reply!

The first image is the First Person Character BP. (Sorry I should have specified that)

The second picture is the Demon_BP (Character BP)

So what I am doing is the following.

The player presses Z (Which is in the FirstPersonCharacter BP)

And it checks if they have authority or not.

If they do it, runs “server increase level” which is set to run on all.

If they do not, it runs “Client increase level” which calls server increase level.

Is this what you are suggesting? I just tried this, and when the server player pushes Z it displays the level increasing, but when a client presses Z, nothing happens at all.

Hi, couple of things:

(-) yes only the owning client can call RunOnServer events on an actor, so if the first image is from the AI bluperint, then that won’t work

(-) don’t use a Multicast for what you’re doing there, better make Level variable to be replicated/repnotify (since you print it once the variable changes, make it repnotify and put the printing logic into the repnotify function). Multicast is usually used for one shot events (e. g. play some sound or particle system), but changing the Level variable seems to should persist (e. g. in progress joins and network culling will break since clients will never receive the new Level if they missed the Multicast)

but I don’t know how I am supposed to
achieve this otherwise

(-) Have the player input in some actor that is owned by the client (e. g. playercontroller), from the player input directly run a RunOnServer event, continue on server and replicate relevant results from server to clients (in this case the Level variable).

Yeah sorry I should have looked more closely at the first image. The target on what you call the RunOnServer event is the Demon BP which is not owned by the client therefore it does not work. Point two and three of my answer still apply though =)

No I meant something like this here

So player input → directly RunOnServer → Server does the rest

Or you could also do it like this here

So player input → client chooses actor where the level should be increased on → server increases level

Ahhh! This worked. I thought I tried everything, but I guess not…

Thank you so much!