Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by sdgd · Aug 16, 2013 at 12:58 PM · c#networkingserverrpcclient

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, ...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sdgd · Aug 16, 2013 at 01:44 PM 0
Share

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

avatar image verenion · Aug 16, 2013 at 01:46 PM 0
Share

Ha! well, keep up the learning. If you get stuck with anything, just pm me.

Thanks :)

avatar image sdgd · Aug 16, 2013 at 01:48 PM 1
Share

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, ...

avatar image verenion · Aug 16, 2013 at 01:49 PM 1
Share

I like the deter$$anonymous$$ation. $$anonymous$$eep at it!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

What's an acceptable network send rate? 1 Answer

How can i send a Player list to every Client 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges