Dynamic material parameter is controlled by wrong player

Here’s the setup:

  1. Each player character has a child actor that’s responsible for the player’s vision cone.
  2. This child actors contains a Post Process component. On Begin Play it creates its own dynamic instance of the base material, which will be used as a post process material, and its own Render Target 2D to be used as a texture parameter in the said material.
  3. It sets the Render Target 2D as the material parameter, and sets the material as the Post Process material.
  4. The material also contains a vector parameter named PlayerLocation that’s supposed to be updated on tick.

If I launch the game with 1 player or as Play Standalone, the vision cones work as intended. But if I launch Play As Listen Server or Play As Client, the PlayerLocation parameters start being controlled by wrong players. The vision cone direction and shape are correct, but the location is not, and it starts following a seemingly random other player instead of the one that owns it.

In my understanding, each actor should have its own dynamic material and they shouldn’t be able to affect each other’s materials, but they do for some reason.

I tried this setup in both Blueprints and C++, and it’s the same. As soon as another player is created, the PlayerLocation parameter breaks.

Why does this happen and how can I fix it?

This is where I set the dynamic material and render target:

And this is the material I’m using:

The first Vector Parameter is PlayerLocation, the TextureObjectParameter is the newly created Render Target 2D.

C++ code just duplicates the same; since it has the same effect, I think the blueprint is a bit easier to read.

I wanted to test it with something simpler that would be more visually representative:

Each character spawns a camera actor, sets itself as a CharacterReference in the camera actor. Camera actor is supposed to follow the character that spawned it. But once there’s more than one character, cameras will often start following the wrong ones, not the ones that spawned them.

I added a PrintString with the name of the CharacterReference in the tick function, and when there are 2 players, it prints 6 times: 3 times for each player. In my understanding it should be printed only once for each character.

As usual, it was my own mistake =)

I messed up when getting references of PlayerControllers, and they were tracking wrong characters.