# NullReferenceException\[SOLVED\]

**URL:** <https://discussions.unity.com/t/nullreferenceexception-solved/787902>\
**Category:** Scripting\
**Tags:** Scripting\
**Created:** [April 27, 2020, 4:24pm UTC](https://discussions.unity.com/t/nullreferenceexception-solved/787902 "2020-04-27T16:24:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GroundstompStudios](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/groundstompstudios/32/114405_2.png) [@GroundstompStudios](https://discussions.unity.com/u/GroundstompStudios)\
**Post date:** [April 27, 2020, 4:24pm UTC](https://discussions.unity.com/t/nullreferenceexception-solved/787902/1 "2020-04-27T16:24:27Z")

</div>

So I haven’t used Photon before, but I’m following a tutorial and the documentation. (The tutorial is for making players connect, etc.) I am getting a NullReferenceException: Object reference not set to an instance of an object error.

I’ll post hastebins if you can help me out. The lines will be marked with where the error is taking place. I’ve been trying to figure this out but i can’t.

[https://hastebin.com/icipevodip.cs](https://hastebin.com/icipevodip.cs) // player movement script  
[https://hastebin.com/vewemomuhu.cs](https://hastebin.com/vewemomuhu.cs) // weapon switching script  
[https://hastebin.com/fodikiduzi.cs](https://hastebin.com/fodikiduzi.cs) // pistol script

The reason I did hastebin was because some of these scripts are long. I feel like this error is happening because it’s always thinking that the player isn’t my player and is just returning false. If you guys need more help, I am using Dani’s player movement script that he made. This has two scripts, one for the head and then the actual movement. The rest is my code. I’m just really confused and im trying to fix it.

---

<div class="post-metadata">

**Author:** ![Kurt-Dekker](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kurt-dekker/32/101578_2.png) [@Kurt-Dekker](https://discussions.unity.com/u/Kurt-Dekker)\
**Post date:** [April 27, 2020, 4:27pm UTC](https://discussions.unity.com/t/nullreferenceexception-solved/787902/2 "2020-04-27T16:27:54Z")

</div>

Whatever you might be doing in Photon is irrelevant here. This is just a nullref, which means one of your variables has not been initialized. The error tells you which line it is on. Identify where that variable is SUPPOSED to be initialized, and see why it might be failing. If you cannot find where it is initialized then you are missing the initialization step, and you must provide one.

---

<div class="post-metadata">

**Author:** ![GroundstompStudios](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/groundstompstudios/32/114405_2.png) [@GroundstompStudios](https://discussions.unity.com/u/GroundstompStudios)\
**Post date:** [April 29, 2020, 2:44pm UTC](https://discussions.unity.com/t/nullreferenceexception-solved/787902/3 "2020-04-29T14:44:35Z")

</div>

> [@Kurt-Dekker](#):
>
> Whatever you might be doing in Photon is irrelevant here. This is just a nullref, which means one of your variables has not been initialized. The error tells you which line it is on. Identify where that variable is SUPPOSED to be initialized, and see why it might be failing. If you cannot find where it is initialized then you are missing the initialization step, and you must provide one.

ill try something. thank you
