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.