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 UDN_9a915d40-27e1-405b-b1cc-83be8be3e71d · Dec 29, 2017 at 03:36 PM · unity 2dservermultiplayer-networking

[SOLVED] 2D Multiplayer: ERROR: Ready with no player object AND NullReferenceException: a null value was found...

Hi! I'm building a 2D Tank game with Unity for the mobile platform.

Here are the errors and warnings I receive when trying to shoot a bullet with my client (not host). These errors are showing up on the host/servers console: https://gyazo.com/8943960658e7db17aad2e10d64f109f7 [Elliots-iPhone] is my iphone (that I'm running the app on). It is the host of the game. Here's my code for shooting a bullet:

 public void ShootBullet() {
         if (isLocalPlayer) {
             Vector3 pos_offset = new Vector3(0, 0, -3f);
             Vector3 bullet_pos = bulletSpawn.transform.position - pos_offset;
             GameObject bullet_fired = (GameObject)Instantiate(bullet, bullet_pos, this.transform.rotation);
 
             CmdShootBullet_Server(bullet_fired);
             Destroy(bullet_fired, 2.0f);
         }
     }
 
     [Command]
     private void CmdShootBullet_Server(GameObject bullet_fired) {
         if (isServer) {
             print("Shoot Bullet called on Server");
             NetworkServer.Spawn(bullet_fired);
         }
     }

I'm not sure if they all are related but I think they are. Here's the detailed information on the red error: https://gyazo.com/e70762d8412c2a0a58ebfbf4e8f29f24

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 UDN_9a915d40-27e1-405b-b1cc-83be8be3e71d · Dec 31, 2017 at 06:04 PM

I solved it. The variable bullet_fired that was passed through as an argument to CmdShootBullet_Server was apparently null. I'm not sure why but i solved it by passing through a Vector3 pos and a Quaternion rotation. I then proceeded to manually creating my bullet instead of using a prefab since that gave some errors. Here's my new code:

 public void ShootBullet() {
         if (isLocalPlayer) {
             Vector3 pos_offset = new Vector3(0, 0, -3f);
             Vector3 bullet_pos = bulletSpawn.transform.position - pos_offset;
             GameObject bullet_fired = (GameObject)Instantiate(bullet, bullet_pos, this.transform.rotation);
 
             Destroy(bullet_fired, 2.0f);
 
             CmdShootBullet_Server(bullet_pos, this.transform.rotation);
         }
     }
 
     [Command]
     private void CmdShootBullet_Server(Vector3 pos, Quaternion rot) {
         if (isServer) {
             print("Shoot Bullet called on Server");
             GameObject shoot_bullet = CreateBullet();
             shoot_bullet.transform.position = pos;
             shoot_bullet.transform.rotation = rot;
             print("POS OF BULLET ABOUT TO FIRE: " + shoot_bullet.transform.position);
 
             // Spawn on clients
             NetworkServer.Spawn(shoot_bullet);
         }
     }
 
     private GameObject CreateBullet() {
         GameObject b = new GameObject();
         SpriteRenderer renderer = b.AddComponent<SpriteRenderer>();
         renderer.sprite = Resources.Load("Sprites/Bullet", typeof(Sprite)) as Sprite;
 
         /*NetworkIdentity network_identity = */b.AddComponent<NetworkIdentity>();
         NetworkTransform network_transform = b.AddComponent<NetworkTransform>();
         Rigidbody2D rigidbody2d = b.AddComponent<Rigidbody2D>();
         CircleCollider2D circleCollider2D = b.AddComponent<CircleCollider2D>();
         b.AddComponent<Bullet>();
 
         rigidbody2d.gravityScale = 0;
         network_transform.sendInterval = 0;
         b.tag = "Bullet";
         b.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
 
         return b;
     }
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

75 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

Related Questions

How do I create a multiplayer turnbased game server? 0 Answers

What is the best way to do Room based multiplayer game? 0 Answers

How to create a room-based multiplayer game that can also be controlled via web interface 1 Answer

Unity networking tutorial? 6 Answers

UNET Discrete Server/Client. ClientRPC? Command? 3 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