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 GAZEREAPER · Dec 24, 2015 at 08:55 AM · networknullreferenceexceptionnull reference exception

NullReferenceException with UNET void

So I started using Unity Networking yesterday, first following the new merry fragmas tutorial and implementing some of that in my own project. After that I wanted to sort of "sync" muzzle flashes, bullets etc. (I spawn a bullet which uses "real" ballistics and uses raycasts to check for hits)

Everything works fine, but when I shoot anywhere with the connected player, it gives this long error:

 NullReferenceException: Object reference not set to an instance of an object
 NetworkedPlayerScript.RpcFire (UnityEngine.GameObject projectile, UnityEngine.GameObject barrel, UnityEngine.AudioClip fireSound, UnityEngine.GameObject[] firingParticles, UnityEngine.GameObject[] deactivateObjectsOnFire, Single reactivateAfter) (at Assets/Resources/Scripts/NetworkedPlayerScript.cs:85)
 NetworkedPlayerScript.InvokeRpcRpcFire (UnityEngine.Networking.NetworkBehaviour obj, UnityEngine.Networking.NetworkReader reader)
 UnityEngine.Networking.NetworkIdentity.HandleRPC (Int32 cmdHash, UnityEngine.Networking.NetworkReader reader) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:652)
 UnityEngine.Networking.ClientScene.OnRPCMessage (UnityEngine.Networking.NetworkMessage netMsg) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:722)
 UnityEngine.Networking.NetworkConnection.InvokeHandler (UnityEngine.Networking.NetworkMessage netMsg) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:208)
 UnityEngine.Networking.LocalClient.ProcessInternalMessages () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/LocalClient.cs:141)
 UnityEngine.Networking.LocalClient.Update () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/LocalClient.cs:69)
 UnityEngine.Networking.NetworkClient.UpdateClients () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:861)
 UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:1044)
 

After struggling with this all day I thought i'd post it here, maybe some of you guys know where I'm being a dumbass.

Here's the part where I get the error:

     [Command]
     public void CmdSendFireNetwork(GameObject projectile, GameObject barrel, AudioClip fireSound, GameObject[] firingParticles, GameObject[] deactivateObjectsOnFire, float reactivateAfter)
     {
         if(!isLocalPlayer)
             RpcFire(projectile, barrel, fireSound, firingParticles, deactivateObjectsOnFire, reactivateAfter);
     }
 
     [ClientRpc]
     public void RpcFire(GameObject projectile, GameObject barrel, AudioClip fireSound, GameObject[] firingParticles, GameObject[] deactivateObjectsOnFire, float reactivateAfter)
     {
         Instantiate(projectile, barrel.transform.position, barrel.transform.rotation);
         barrel.GetComponent<AudioSource>().PlayOneShot(fireSound);
 
         foreach (GameObject ps in firingParticles)
         {
             ps.GetComponent<ParticleSystem>().Play();
         }
         MuzzleFlash(deactivateObjectsOnFire, reactivateAfter);
     }
 
     private IEnumerator MuzzleFlash (GameObject[] deactivateObjectsOnFire, float reactivateAfter)
     {
         foreach (GameObject go in deactivateObjectsOnFire)
         {
             go.SetActive(true);
         }
         yield return new WaitForSeconds(reactivateAfter);
         foreach (GameObject go in deactivateObjectsOnFire)
         {
             go.SetActive(false);
         }
     }
 
     [Command]
     public void CmdBulletHitPlayer(GameObject hit)
     {
         hit.GetComponent<NetworkedPlayerScript>().RpcResolveHit();
     }

(this isn't the full script of course) This part of code is attached to the player which contains all the network components needed. The bullet that is supposed to instantiate is only a dummy projectile just so other players can see the bullet, the real bullet checking if it hit a player is only local.

I know I am probably doing a lot of this wrong but forgive me because it's my first time working with Networking.

Basically what happens is this; Gun fires, it tells the player object all the parameters (CmdSendFireNetwork), CmdSendFireNetwork checks if bullet was shot by the local player, if it isnt it sends all the parameters to the network only to be received again in RpcFire(), problem is, RpcFire says the error: "NullReferenceException: Object reference not set to an instance of an object".

I'm totally clueless, I also printed all the parameters in CmdSendFireNetwork just to make sure it got everything it needed, then I also printed all the parameters in RpcFire but as soon as it is called the error appears.

Please help me, and please ask for more info if you need it to answer my question.

Thanks community :)

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Null Reference in Line 0 1 Answer

Null Reference Exception, what is it and why do I get it? 1 Answer

NullReferenceException: Object reference not set to an instance of an object 2 Answers

Why am i getting a NullReferenceException when i switch platform to Android? 0 Answers

Networking-multplayer issue 1 Answer


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