# Null Reference Exception (Survival Shooter Tutorial)

**URL:** <https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424>\
**Category:** Unity\
**Created:** [September 12, 2017, 6:29pm UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424 "2017-09-12T18:29:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Viking885](https://avatars.discourse-cdn.com/v4/letter/v/f17d59/32.png) [@Viking885](https://qa.fmod.com/u/Viking885)\
**Post date:** [September 12, 2017, 6:29pm UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/1 "2017-09-12T18:29:29Z")

</div>

I am currently working through the FMOD Survival Shooter Tutorial. I recently rewritten the code into the enemy\_health script which would call the Hellphant hurt event when the enemy was hurt. However, when I play the game, the guns bullet pass through the enemy characters and I am given the following error message:

" NullReferenceException: Object reference not set to an instance of an object  
CompleteProject.EnemyHealth.TakeDamage (Int32 amount, Vector3 hitPoint) (at Assets/\_Complete-Game/Scripts/Enemy/EnemyHealth.cs:61)"

“CompleteProject.PlayerShooting.Shoot () (at Assets/\_Complete-Game/Scripts/Player/PlayerShooting.cs:111)”

“CompleteProject.PlayerShooting.Update () (at Assets/\_Complete-Game/Scripts/Player/PlayerShooting.cs:49)”

How would I go about fixing this ?. I am also using a mac if there are any potential inconsistencies.

Thanks

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [September 12, 2017, 10:41pm UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/2 "2017-09-12T22:41:32Z")

</div>

NullReferenceException means that you are trying to perform an action on an object that has not been assigned/initialized. Unity does a good job of telling you exactly where these issues come from in the console window.

Eg.  
Assets/\_Complete-Game/Scripts/Enemy/EnemyHealth.cs:61 refers to Line 61 of the EnemyHealth.cs file. You can either attach a debugger as you run the project or even use print logs to see what variables have been assigned at that time.

---

<div class="post-metadata">

**Author:** ![fla5hback](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@fla5hback](https://qa.fmod.com/u/fla5hback)\
**Post date:** [June 6, 2026, 2:17pm UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/4 "2026-06-06T14:17:56Z")

</div>

Hey there,

I know I’m late to the party, but the problem is still there. There is something wrong with “eventEmitterRef.Play()” implementation. If I put it there, I’ll get the same NullReferenceException every time a bullet passes through an enemy (not HITTING the enemy!), and there is no damage done (Same as OP). As I’m not a professional Unity programmer, I also don’t know what to look for in debugging.

This is the exception I’m getting:  
NullReferenceException: Object reference not set to an instance of an object  
CompleteProject.EnemyHealth.TakeDamage (System.Int32 amount, UnityEngine.Vector3 hitPoint) (at Assets/\_CompletedAssets/Scripts/Enemy/EnemyHealth.cs:62)  
CompleteProject.PlayerShooting.Shoot () (at Assets/\_CompletedAssets/Scripts/Player/PlayerShooting.cs:111)  
CompleteProject.PlayerShooting.Update () (at Assets/\_CompletedAssets/Scripts/Player/PlayerShooting.cs:49)

The “EnemyHealth.cs.62” is exactly where the “eventEmitterRef.Play();” is sitting. If I comment this line, everything goes back to normal.

I’m using FMOD 2.03.13 and Unity 2022.3.22f1 on Windows 11.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [June 8, 2026, 5:26am UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/5 "2026-06-08T05:26:45Z")

</div>

Hi,

Thank you for bringing this to our attention.

Has the `eventEmitterRef` variable been assigned an [Unity Integration | Game Components - Studio Event Emitter](https://fmod.com/docs/2.03/unity/game-components.html#studio-event-emitter) either in the editor:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/b/b8e876c191702dc6843d6a197dffc04350e01a5b.png)

or via code with something like this:

```csharp
public FMODUnity.StudioEventEmitter eventEmitterRef = null;

void Start()
{
    eventEmitterRef = GetComponent<FMODUnity.StudioEventEmitter>();
}

```

Which video did you get up to before hitting this issue?

---

<div class="post-metadata">

**Author:** ![fla5hback](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@fla5hback](https://qa.fmod.com/u/fla5hback)\
**Post date:** [June 12, 2026, 12:46am UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/6 "2026-06-12T00:46:34Z")

</div>

Hello again, and thanks for the reply.

I actually got frustrated and moved on to another tutorial series, hence the late answer.

I was on [this video](https://www.youtube.com/watch?v=nnT2-ldNEHs)(10:12 to 11:37) and did things same as in the video. So I have used the second method (assigning the eventEmitterRef variable via code).

Now that you’ve mentioned another approach, I tried that, too, but got the same error on the same line again.

Is there any additional information I can provide to help you replicate or tackle the error?

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [June 19, 2026, 12:41am UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/7 "2026-06-19T00:41:45Z")

</div>

Thanks for the info.

From the video I think we need to make sure that for the prefab `Assets/_CompletedAssets/Prefabs/Hellephant.prefab` it has the event emitter added to it

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/0/087ec085e69349ca5b3ea9bb6b11be65e5405dba.png)

So that our script can pick it up:

```csharp
void Awake ()
{
    // Setting up the references.
    anim = GetComponent <Animator> ();
    enemyAudio = GetComponent <AudioSource> ();
    hitParticles = GetComponentInChildren <ParticleSystem> ();
    capsuleCollider = GetComponent <CapsuleCollider> ();

    // Setting the current health when the enemy first spawns.
    currentHealth = startingHealth;

    // Grab emitter from the game object
    eventEmitterRef = GetComponent<FMODUnity.StudioEventEmitter>();
}

```

Could I please grab a screenshot of your `Hellephant` prefab?

---

<div class="post-metadata">

**Author:** ![fla5hback](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@fla5hback](https://qa.fmod.com/u/fla5hback)\
**Post date:** [June 20, 2026, 9:33pm UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/8 "2026-06-20T21:33:36Z")

</div>

Sure, here you are

 ![Untitled](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/8/8a269797a937b3793c71177635eca3af039ae214.jpeg)

I’m pretty sure everything is in place and I haven’t missed anything. The error I’m facing only occurs when `eventEmitterRef.Play()`is present. When I comment it everything goes back to normal. It looks like this method somehow disrupts the code related to enemy collider recognition by player’s bullets.  
The NullReferenceException provided in my first post mentions other methods such as `CompleteProject.PlayerShooting.Shoot ()` and `CompleteProject.PlayerShooting.Update ()`. It seems that `eventEmitterRef.Play()`is just the starting point and the main issue occurs somewhere else.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [June 26, 2026, 2:12am UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/9 "2026-06-26T02:12:17Z")

</div>

Thanks for confirming that, would it be possible to upload your full `EnemyHealth.cs` file as a `txt` files? I can add it to my `SurvivalShooter` project to see if I can preproduce the issue.

---

<div class="post-metadata">

**Author:** ![fla5hback](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@fla5hback](https://qa.fmod.com/u/fla5hback)\
**Post date:** [June 26, 2026, 2:54am UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/10 "2026-06-26T02:54:37Z")

</div>

Sure,

[EnemyHealth.txt](https://qa.fmod.com/uploads/short-url/wvRmLng5BAOap6SbKIvfjz0Zg7P.txt) (4.1 KB)

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [July 1, 2026, 1:22am UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/11 "2026-07-01T01:22:08Z")

</div>

Thank you for the script. I was able to add it to my `Hellephant.prefab` and get it to trigger the event emitter without issue.

Another thing to try is just manually assigning the emitter reference to make sure it is always there:

![Reference](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/b/b6384ec758b76ce4195211bcb5b2f7cbc6c90b07.gif)

---

<div class="post-metadata">

**Author:** ![fla5hback](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@fla5hback](https://qa.fmod.com/u/fla5hback)\
**Post date:** [July 3, 2026, 11:23am UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/12 "2026-07-03T11:23:41Z")

</div>

Thanks for your time and effort.

I have already tried that, too. Now I’m sure this problem is unsolvable in my case, and I think it’s a bug for this exact fmod and Unity version integration (which isn’t even worth trying to pin down and solve in my opinion).

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [July 5, 2026, 11:18pm UTC](https://qa.fmod.com/t/null-reference-exception-survival-shooter-tutorial/13424/13 "2026-07-05T23:18:48Z")

</div>

Thank you for your assistance investigating the issue. If there is anything else we can do to help, please do not hesitate to ask.
