Hello
I have a problem with changing the material of a static mesh at runtime, in a multiplayer game. The situation is as follows:
In my [FONT=Courier New]GameMode class, I have a [FONT=Courier New]TArray of [FONT=Courier New]TeamStarts, that are basically [FONT=Courier New]PlayerStarts but represented as a capturable area, with a flag (like a capturable flag on a Battlefield Conquest map).
In the constructor, I create the mesh, load and store the materials that will represent the 3 state of the flag (one material for the first, one for the second team and one for the neutral state), and set everything to default (so every flag is neutral at first).
Because we can place a [FONT=Courier New]TeamStart on the map and edit who controlls it, in the [FONT=Courier New]BeginPlay, I re-set the material of the flag, based on who controlls it, then add this flag to the [FONT=Courier New]TeamStarts [FONT=Courier New]TArray in the [FONT=Courier New]GameMode.
In my function, that handles the capture of a flag, I set the material of the flag with the [FONT=Courier New]SetMaterial(…) function, if it’s state has changed (i.e. someone neutralized or captured it).
When I hit play, everything is correct, because every flag has the right material set, but when I neutralize or capture a flag it remains the same as it was on start.
To solve the problem, I tried all sorts of things like:
Setting the meshes and the materials as [FONT=Courier New]Replicated in the [FONT=Courier New]TeamStart class
Creating a variable (tried with [FONT=Courier New]UMaterialInterface and with an [FONT=Courier New]FLinearColor for the [FONT=Courier New]UMaterialInstanceDynamic) with a [FONT=Courier New]ReplicatedUsing specifier that I changed from the [FONT=Courier New]GameMode, and in the [FONT=Courier New]OnRep_ function, I set the mesh’s material to this variable’s material (or when I used an [FONT=Courier New]UMaterialInstanceDynamic, I set the dynamic material to the set [FONT=Courier New]FLinearColor)
Creating a [FONT=Courier New]UMaterialInstanceDynamic from a material and just change the base white color to somehing different (for example to red) on state change with [FONT=Courier New]SetVectorParameterValue(…)
Handling the setting of the mesh material in Blueprint in a way, that is really similar to the Networking Content Example’s traffic light
but nothing seems to work.
I’m not sure, if the problem is the replication (although I launched the game with one player as the server, but the material hasn’t changed there either) or the fact that changing a mesh’s material at runtime is not possible or not possible in every way (although I tried the [FONT=Courier New]UMaterialInstanceDynamic method too, that I read here on the forum, is the right way of changing a mesh’s material’s parameters at runtime).