Runtime GameObject in multiplayer

Good day, community!

I’m creating a game with procedural terrain, and everything works fine, but one thing i can’t understand is how to exactly create a new gameobject through script in multiplayer?

GameObject go = new GameObject("("+pos.x+" "+pos.y+" "+pos.z+")", typeof(MeshFilter), typeof(MeshRenderer), typeof(ChunkRenderer), typeof(NetworkView));

Here is the code. Got any ideas how to perform this in multiplayer? Network.Instantiate is not what i’m looking for.

Thanks for your attention!

I don’t know what a ChunkRenderer is, is this a custom class of yours?

I don’t know why Network.Instantiate isn’t what you’re looking for, but I’m guessing it’s because you’re trying to send the procedurally generated terrain data across the network. If this is the case, you’re going to have a bit of a problem. The only way to get data like that across the unity network is to A) Serialize it, send it, then deserialize it or B) Find a way to get around sending the data.

First, you want Network.Instantiate (despite what you say). This will spawn in a base gameObject from your Prefab folder. The next thing you need to do is make a Remote Procedure Call (RPC). This RPC’s job is to tell your new gameObject how to behave. If you’re sending terrain data, you will probably provide gameObject with a list of Vector3s which it will then apply to itself to look exactly like the terrain in your sending client.

It’s hard to give more info without knowing exactly what you want to do. But in short, Network.Instantiate IS what you want. But then you need to tell that gameObject how to be.

Thanks for your answer, BadAssGamer. I don’t really know why i made that question, lol.

Solution here:

GameObject go1 = new GameObject("("+pos.x+" "+pos.y+" "+pos.z+")", typeof(MeshFilter), typeof(MeshRenderer), typeof(ChunkRenderer), typeof(NetworkView));
    		GameObject go = Network.Instantiate (go1, new Vector3 (0, 0, 0), Quaternion.identity, 0) as GameObject;