- Home /
Troubles with using NetworkViews on a server
Is there a way to make a server send data via a NetworkView without the server having to apply the data itself? For example:
The client sends its position to the server via a NetworkView
The server sets the player's position in its Players array, or something similar, so it can keep a record of where the player is
The server sends the new position to other players
It seems like Unity wants me to have the server Instantiate its own Player prefab, and send the data through a NetworkView like that. I don't want the server to have players running around in its Scene; I want to save the position in a custom Player class in the server's Players array, and then send the data out to other players so they can extrapolate/interpolate it.
So my question is, is there any way to use the server just to relay the data to other players, without trying to apply the data to the GameObject that has the NetworkView? I also don't want the server to have to Instantiate all of the Player prefabs itself; only the players should do that, otherwise I'd have a bunch of players that aren't even part of the same session running around in the Scene.
Hopefully this is explained clearly enough. Thanks to anyone who tries to help!
Create an empty game object with a network view for the server is not what you want ? It avoids a player instantiation for the server.
I was doing that, but I set the NetworkView's "observed" variable to the Player.js on the client side, and manually Serialize()'d the position in the Player.js script (ins$$anonymous$$d of setting 'observed' to the Transform, because I thought I'd need to Serialize() more values later). However, the server doesn't have a Player.js script to observe.
I just now tried it by giving the Server.js an OnSerializeNetworkView() event that sets the position in the servers' Players array. I had the Server set its NetworkViews to observe the Server script. I put a Debug.Log() in there so I could see if it was getting the calls, and it was (without any errors). But is that O$$anonymous$$ to do? One NetworkView is observing Player.js, and the other is observing Server.js.
I thought they both had to observe the same thing, which was why I thought Unity was going to force me to Instantiate the Players on the server as well...
Your answer
![](https://koobas.hobune.stream/wayback/20220613085845im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
networkview.RPC not accessible in unity 5.4 1 Answer
UNET - Send update positions at a lower level than using NetworkTransform? 0 Answers
How to load all character previously in game when new player joins 0 Answers
How to send UDP updates form server to each Client? 0 Answers
State synchronization non-functional after mode change? 0 Answers