I'm currently working on a plugin and came across the idea being able to spawn objects that are not normally available in the game. I have tried several methods of doing this but all have failed.
Is this even possible? If anybody has a clue on how to do this that would be greatly appreciated.
Thanks!
Spawning primitive Unity objects?
Discussion in 'Hurtworld Development' started by danmw3, Jan 2, 2016.
-
Wulf Community Admin
What specifically are you trying to spawn? I don't think you'd be able to spawn anything that doesn't already exist in both the client and server, and there's most likely no way for the client to actually know it exists, only the server.
-
That was my first thought. I came to the conclusion that I would only be able to spawn gameobjects that come with the Unity engine or game. I'd like to just be able to spawn primitive objects such as cubes.
Code:GameObject.CreatePrimitive(PrimitiveType.Cube);
-
Wulf Community Admin
-
Are you aware of if there is any way to let the client know of these objects and not just the server?
-
Wulf Community Admin
I'm assuming the'd need to be sent to the client, but without them actually being used by the game generally, then there's likely nothing setup to send them. -
Another forum member, Kodfod, said that he was trying to do something similar and was able to get collision between the cube and player to work but the player could not see the cube itself. He currently hasn't told me how he did it.
-
Wulf Community Admin
-
I'll keep this thread updated if I discover anything.
Do you know how to use RPC in a plugin? -
Wulf Community Admin
-
Can you give some examples? I haven't really looked into RPCs, I just know they exist.
-
Wulf Community Admin
-
Well I found NetworkEntityManagerPlayerServer that has an RPC method which is why I brought this question up. Is that what I should be looking for?
-
How we spawn entities on the client and server (so both know about each other) is through NetworkManager.Instance.Instantiate. However, there are a few requirements for that to work:
- Your object must have a uLink.NetworkView component attached on both proxy and server versions
- Your server object must have a NetworkInstantiateConfig component attached. This tells the game about what object the client should spawn to represent this server object, and handles network lodding/pooling
- You must add the server object network view to the array NetworkObjectPool.Instance.NetworkPrefabObjects
I'm not entirely sure if this will work at runtime. Let me do a quick experiment to find out.
Edit: Having a play around, I can't see an easy way to do this. I'll keep having a poke around though. The biggest problem is that both client and server have to know about an object to instantiate it, and there's currently no method for propagating that information from server to client.
This is definitely something we want to support though!Last edited by a moderator: Jan 13, 2016