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
0
Question by Sephius · Jul 14, 2013 at 12:16 AM · c#networksendreceive

[c#] Basic Network data sending / receiving

Hello there !

I'm doing some tests with Networks and i need some help on the basics data sending/receiving.

What i want to do is to store a player's name into an array when this player connect to the server. I already have a working connection to the server, but i don't really understand how i can send data to the server (like a string or an integer). I tried to use RPC, but i got an error.

    private string[] sPlayersNames = new string[Constantes.MAX_PLAYERS];  //i want the player's name stored here (server side)
     private string sPlayerName;  //this is the variable that contain the player name (client side)
     NetworkView nvNetworkView = new NetworkView();
         
     void OnConnectedToServer()
     {
           Debug.Log ("Successfully connected to server !");
           //Here, i want to send the name of the player
           nvNetworkView.RPC ("SetName", RPCMode.Server, sPlayerName);  //error here
     }
             
     [RPC]
     void SetName(string sName)
     {
         sPlayersNames[iPlayerCount] = sName;
         Debug.Log("Name recieved !");
     }

I got the following error (client side) :

NullReferenceException UnityEngine.NetworkView.RPC (System.String name, RPCMode mode, System.Object[] args) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/Networking.cs:383) NetworkManager.OnConnectedToServer () (at Assets/Cs/NetworkManager.cs:94)

May somebody help me with that ?

Please escuse me if the question has already been asked. Thanks for your time.

Have a wonderfull day/night :)

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
0
Best Answer

Answer by Benproductions1 · Jul 14, 2013 at 02:48 AM

Hello,

Your problem is, that you are treating a NetworkView as a standard class, when in fact, it is a component (An extension to MonoBehaviour).

Although it compiles fine, you can't simply go new NetworkView(). Instead I suggest manually adding a NetworkView to the object and building the reference from GetComponent.
You should also add @script RequireComponent(NetworkView) so that you will never forget to add it again ;)

Hope this helps,
Benproductions1

Comment
Add comment · Show 2 · 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 Sephius · Jul 14, 2013 at 03:02 AM 0
Share

Thank you so much ! I tried it, it works perfectly !

avatar image Benproductions1 · Jul 14, 2013 at 03:06 AM 0
Share

Just as a note, It's smart to look at some tutorials of how these things work, before asking questions like this :)

TBO I just read the first 3 lines of your code and answered the question. I never read anything else

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Really quick/easy question about RPCs 1 Answer

Send Prefab by RPC? 1 Answer

How do I transfer my network between scenes? 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