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 Sm1Ling · Apr 22, 2020 at 09:55 AM · multiplayercrashnullreferenceexceptionmultiplayer-networkingobject-reference-error

How to Connect Difficult Object using UnityEngine.Network

My idea is to make multiplayer game based on physics and collisions. All the movings of characters are created by movings and rotation of Main body. I mean I have Sphere as main body, Shoulders as child with fixedRigidbody, hands as childs connected with Character Joint to the shoulders. Sword (on the same level as body) Connected with Characted Joint to the hand, Camera(on the same level as body) with the script To follow the body. And all that stuff is under Empty Player Object.

alt text

That should be the Player prefab for Network, however i met difficulties with synchronizing of all the parts of the player on the server, because only parent GameObject might have NetworkIdentity and NetworkTransform.

Thus i decided to instantiate parts of the body while the playig on server. EmptyPlayer Prefab contains script with method [Command] void CmdPlayerSpawn() that contatins links on the prefabs connected in inspector and their NetworkServer.SpawnWithClientAuthority. Moreover links of Joints were also added(Sword to hand) (Camera to follow body) alt text

 [Command]
     void CmdPlayerSpawn()
     {
         _body = (GameObject)Instantiate(body, transform.position, Quaternion.identity);
         NetworkServer.SpawnWithClientAuthority(_body, connectionToClient);
 
         _sword = (GameObject)Instantiate(sword, _body.transform.Find("LeftGlove").position + Vector3.up, Quaternion.Euler(0,0,0));
         NetworkServer.SpawnWithClientAuthority(_sword, connectionToClient);
         _sword.GetComponent<CharacterJoint>().connectedBody = _body.transform.Find("LeftGlove").GetComponent<Rigidbody>();
 
         _camera = (GameObject)Instantiate(camera, transform.position+ Vector3.up*8, Quaternion.Euler(40,0,0));
         NetworkServer.SpawnWithClientAuthority(_camera, connectionToClient);
         _camera.GetComponent<CameraBehaviour>().objectToFollow = _body;
         Cameralink = _camera.GetComponent<Camera>();
     }

AAAND. I am trying to play. While playing as host everything goes ok. Player is quite... playable. BUT As soon as i connect from other simulation as Client the client game crashes(throws NullReferenceExeptions) and Spawns 2 PlayerObjects (LMAO) ((that is seen on the host player account lol). I really cant understand how to execute my idea.

May be you could help me?

character1.png (168.9 kB)
character2.png (110.2 kB)
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 Sm1Ling · Apr 22, 2020 at 11:04 AM

While Host While client


character3.png (460.6 kB)
character4.png (358.0 kB)
Comment
Add comment · 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

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

222 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Odd behaviour when trying to re-connect/host after disconnecting 0 Answers

weird NullReferenceException 1 Answer

Network FPS Input Controller problem 1 Answer

Bullets Only Spawning on Host Client... (a uNet problem),Multiplayer Connected Client Not Spawning Bullets, But Host the is... 0 Answers

Looking for a solution to multiplayer 2 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