Change an actor size on client-to-server side using a variable from PlayerCharacter

Hi everyone.

I’m trying to make a simple system where whenever a player (server or client) presses a key, a cube will change size to all other players. I’m using a variable from PlayerCharacter because the idea is to use the microphone on the future.
But my problem is, I can replicate from server to client, but when I try on client, neither client or server can see the changes.
How can I press a button on Client side to make this cube changes for everyone?

Thank you.



The character part seems mostly correct, except that Log(1) equals 0 so not sure what you’re trying to accomplish there. If you want the volume to fade in, I suggest setting up a simple timeline where you can even control the curve.

Mic loudness is a replicated variable, so it should replicate to every player.
Now you want to bind the cube’s size to the loudness. There are two ways you can go about this :

  • either you update the cube from the character code, whenever mic loudness is updated
  • or you do it from cube code by tracking changes in character, which is what you tried to do

In both cases, there is a question of binding the two together. Is there only one cube in the level, or is there one per player ? If there’s only one, who controls its size ?

Anyways I’m gonna assume there is one per player, otherwise it doesn’t make much sense. if that is the case, at some point you have to spawn the cube for the player. At this moment you can easily store a reference to the spawned cube, somewhere in the player’s variables, or, pass the player/character to the spawned cube so you can store a reference to the player in the cube’s variables.

If you want to stick with second approach, you can pass the player character as the “Owner” pin of the spawned cube. Owner is a builtin variable that can be any actor. Then, in cube code, instead of using “Get Player Character 0”, you can use “Get Owner” which refers to the correct player.

Your MicLoudness variable is already replicated, and SizeIncrease can be directly inferred from it, so there’s no need to replicate SizeIncrease. Tick executes on both server and clients, so you can just update SizeIncrease according to MicLoudness, without further replication.

In event Tick you are using the result of a node executed in BeginPlay. This is very bad practice, especially using the result of a validated Get/Cast. If your cast was successful at BeginPlay, but then during gameplay the character is destroyed, then the Tick function will continue accessing it directly and spam errors. If the cast was unsuccessful at BeginPlay due to a race condition, and then the character becomes valid, the output pin will never be updated. You should move all code in Tick and remove BeginPlay as you don’t need it there.

Thanks for the reply.

I should indeed have had started with this information. I’m using the ThirdPersonTemplate where 2 players should be seeing the same cube changing on the map (so 1 cube for everyone). Video attached.

The final idea is to have players changing the same actors whenever they talk on the mic, but for testing purposes I’m just triggering the variable with the Z key. The effect that I want is the same as this tutorial (12:05): https://youtu.be/d3spCky0FIc?t=727

When I trigger the MicLoudness with the “Z” button on server-to-client side the changes looks ok, but from the client side it returns that the variable is being changed on server side (right?), but the cube is not changing on either client nor server.

If all players control the same cube, then you probably don’t want to do that logic in the cube BP. The cube would have to continuously track when new characters are created in the world, and track each character for changes in their MicLoudness variable. That is not practical.

Instead, since there is a single cube, you can easily fetch it from the character BP, and update it. So the simplest way would be to use Tick from character BP, find the cube using “Get Actor From Class”, and update the cube using MicLoudness.

Once that works you should consider optimizing a bit :

  • Move the GetActorFromClass into BeginPlay instead of tick, store the result in a variable
  • Use RepNotify (from MicLoudness) instead of Tick, and update the cube from the notify event. If you need overtime update, start a timeline from the notify event.

But if I want to increase the number of actors instead of just 1 cube, wouldn’t that be not pratical to do everything in the CharacterBP?

Also I’ve changed the cube blueprint to change in a fixed value from a variable in the cube itself and it works just as expected. The client overlap the trigger box and changes the variable on the server, making it visible on both sides.

I think the problem is that, when pressing the “Z” key to change the characterBP variable “MicLoudness”, the client side is not sending the information for it to change on the server side, correct? Shouldn’t that work since I’m using a CustomEvent to change the characterBP variable which is set to “run on server”?