- Home /
Network how to send data/activate function
I'm just beginning to learn networking, ...
I did read all the unity reference:
http://docs.unity3d.com/Documentation/Components/NetworkReferenceGuide.html
and I couldn't figure out a thing how to even start, ...
than I followed this on youtube till step 4
but I want it to work separatly (server script and client script)
and I get an error, but I can connect to server ok.
MissingComponentException: There is no 'NetworkView' attached to the "_Networking" game object, but a script is trying to access it.
You probably need to add a NetworkView to the game object "_Networking". Or your script needs to check if the component is attached before using it.
I have server/client attached to empty GO _Networking,
for server I disable client script and build & run it.
for client I activate client and disable server script and run it under unity it self, but change color button produces me an error.
where am I going wrong?
both scripts:
Server
using UnityEngine;
using System.Collections;
public class Server : MonoBehaviour {
public GameObject Planet;
public string IP = "127.0.0.1";
public int Port = 25001;
void OnGUI (){
if (Network.peerType == NetworkPeerType.Disconnected){
if (GUILayout.Button("Start Server")){
Network.InitializeServer(10, Port);
}
}
else {
if (Network.peerType == NetworkPeerType.Server){
GUILayout.Label("Server");
GUILayout.Label("Connections: " + Network.connections.Length);
if (GUILayout.Button("Logout")){
Network.Disconnect(5);
}
}
}
}
[RPC]
void ChangeColor (){
Planet.renderer.material.color = Color.green;
}
}
Client
using UnityEngine;
using System.Collections;
public class Client : MonoBehaviour {
public GameObject Planet;
public string IP = "127.0.0.1";
public int Port = 25001;
void OnGUI (){
if (Network.peerType == NetworkPeerType.Disconnected){
if (GUILayout.Button("Start Client")){
Network.Connect(IP,Port);
}
}
else {
if (Network.peerType == NetworkPeerType.Client){
GUILayout.Label("Client");
if (GUILayout.Button("Change collor")){
networkView.RPC("ChangeColor", RPCMode.All);
}
if (GUILayout.Button("Logout")){
Network.Disconnect(5);
}
}
}
}
[RPC]
void ChangeColor (){
Planet.renderer.material.color = Color.green;
}
}
thanks in advance just a gently push in right direction will be nice, ...
Answer by verenion · Aug 16, 2013 at 01:09 PM
You probably need to add a NetworkView to the game object "_Networking". Or your script needs to check if the component is attached before using it
It pretty much tells you what's wrong there. On the GO "_Networking", add a NetworkView component. On the right where it says "Add Component", I think Network View is under Miscellaneous. ANY object that uses any of the networking functions needs a network view attached. When you add the network view, turn state synchronization off and make sure the "Observed" object is none. Otherwise, it will try to automatically synchronise the state of the _networking object, which isn't what you want.
oh thanks, ...
complettely forgot that part
I thought how it's not networkview in there I just wrote it, ...
and my knowledge to read properly debug has grown a little, ...
I'm still many times experiencing reading debug and don't know what it wants but if I look at the code I know what's wrong.
thanks for tellying me more about network view and it's sinhronization :)
I'd give you 2 thumbs up if I could
Ha! well, keep up the learning. If you get stuck with anything, just pm me.
Thanks :)
I always get stucked but after 4 hours of learning and trying to figure out I usually go ask here.
but usually before 4 hours I figure it out on my own.
networking is really totally new ground to me, ...
I like the deter$$anonymous$$ation. $$anonymous$$eep at it!
Your answer
Follow this Question
Related Questions
RPCMode.Server works in one spot but not another 0 Answers
ClientRpc not called on Client 1 Answer
Network RCP between client server projects 0 Answers