Hi I am wondering how I can edit a PhysicsCollider on an entity in both server and client worlds in a MonoBehaviour? Basically what I’m trying to do is take a runtime generated mesh and add a PhysicsCollider on it. Right now it is only adding it in the Server world and not the Client world. Since PhysicsCollider is not a GhostComponent, I’m not sure how to do this. The entity is being baked with a Ghost Authoring Component.
One Suggestion
You can make the mesh generation deterministic and generate the same mesh + collider on the clients and server.
Use the ConvertToGhostPrefab
method: Class GhostPrefabCreation | Netcode for Entities | 1.4.0
Instantiate on the server but the creation of the GhostPrefab happens on both client and server.
Example: EntityComponentSystemSamples/NetcodeSamples/Assets/Samples/CustomSerializer/CustomSerializerSample.cs at master · Unity-Technologies/EntityComponentSystemSamples · GitHub
That works! Though when running both worlds on the same machine (like when a player is hosting or in the editor) I had to run it on both worlds like so
World serverWorld = null;
World clientWorld = null;
var allWorlds = World.All;
for (int i = 0; i < allWorlds.Count; i++) {
var w = allWorlds[i];
if (w.Name == "ServerWorld")
serverWorld = w;
if (w.Name == "ClientWorld")
clientWorld = w;
if (serverWorld != null && clientWorld != null)
break;
}
if (clientWorld != null) {
// Create prefab and convert to ghost with clientWorld.EntityManager
}
if (serverWorld != null) {
// Create prefab and convert to ghost with serverWorld.EntityManager
// Instantiate prefab on server
}