Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ArcticPinou · Jan 13, 2016 at 02:15 PM · networkingunity5rpcclientdelete

NetworkManager auto deleting client gameobject when calling it

Hi everyone, first I want to tell that my english is not perfect.

So here is my problem : I have a _GM gameobject with a NewtorkManager herited script attached, and for ClientRpc methods I use the automatically generated client gameobject. I have already done a button in my UI that call a ClientRpc method on the client gameobject to synchronize some variables through all clients, it works.

To access the player gameobject I did a static function that return the instance of the player's gameobject . NetworkPlayer is the script attached to players gameobjects. Buuut when I try to call the

 NetworkPlayer.PlayerGameobject.GetComponent<NetworkPlayer>().RpcTellClientPlayerNumber(numberOfPlayer);

I get an error : Object reference not set to an instance of an object.

If I delete the line from the NetworkManager herited script, the client's gameobject appear in my scene, if I call the gameobject, it will disappear.

There is no lines of code into the "RpcTellClientPlayerNumber(int a)" method ...

Idk what to do. Is the static return of the gameobject a problem ? That just make no sense.

Thank you for reading this and eventually for a response.

PS: My NetworkManager herited script & my networkplayer script : http://image.noelshack.com/fichiers/2016/02/1452692996-aze.png <= The LAST line of code http://image.noelshack.com/fichiers/2016/02/1452692996-qsd.png http://image.noelshack.com/fichiers/2016/02/1452693199-wxcv.png http://image.noelshack.com/fichiers/2016/02/1452693145-wxc.png

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

Answer by ashleyjlive · Jan 14, 2016 at 10:28 PM

I believe the problem lies with PlayerGameobject being null as it is not set before you call this line of code. Remove the line "NetworkPlayer.PlayerGameobject.GetComponent().RpcTellClientPlayerNumber(numberOfPlayer);"

Insert this into your ServerManager script.

public static ServerManager s_Singleton;

void Awake () { s_Singleton = this; }

Then in the Start method of the NetworkPlayer Script insert

if(isServer) { RpcTellClientPlayerNumber(ServerManager.s_Singleton.numberOfPlayer); }

See if that works. Sorry for the code formating.

Comment
Add comment · Show 1 · 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 ArcticPinou · Jan 18, 2016 at 09:49 AM 0
Share

Thank you for the anwser, I understand better what I did wrong, the "start" method of the networkplayer script ofcourse is executing after the OnServerConnect event, didnt realized that. I tried what you told me to do, but now I have an error at the very first line of my networkmanager's start script

 void Start ()
     {
         Network$$anonymous$$anager.singleton.networkPort = Random.Range(7777, 32000); <= I get the error of Object reference on this line
         Debug.LogError(Network$$anonymous$$anager.singleton.networkPort);
         Network$$anonymous$$anager.singleton.StartHost();
     }

and when I put the "void Awake () { s_Singleton = this; }" into commentary, the problem disappear, it is like this line is preventing player from spawning. I will search myself but if you can help again I will appreciate it, thanks anyway

Edit : The problem does come from the "Awake" call, it is weird but it seems to work. Thank you ! If you can explain why the Awake fonction make the error that would be nice :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Network RCP between client server projects 0 Answers

ClientRPC not getting sent. 0 Answers

Why is my script variable NULL in a ClientRPC??? 1 Answer

iOS IL2CPP Networking Issues Unity 5.0.x 3 Answers

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