# Sim error: failed cast on null

**URL:** <https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618>\
**Category:** Help\
**Created:** [January 26, 2023, 10:07pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618 "2023-01-26T22:07:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![BruceSchwa](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@BruceSchwa](https://forum.makecode.com/u/BruceSchwa)\
**Post date:** [January 26, 2023, 10:07pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/1 "2023-01-26T22:07:38Z")

</div>

My student keeps getting Sim error: failed cast on null. We can’t seem to figure out why. [https://makecode.com/\_LVKM6fR641qc](https://makecode.com/_LVKM6fR641qc)

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [January 26, 2023, 10:52pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/2 "2023-01-26T22:52:10Z")

</div>

What I’ve noticed is that this game sets the trash positions before it actually declares the trash sprites. You could fix this problem by taking out the ‘if any button pressed’ in the ‘on start’ event. I hope this helps! 🙂

---

<div class="post-metadata">

**Author:** ![BruceSchwa](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@BruceSchwa](https://forum.makecode.com/u/BruceSchwa)\
**Post date:** [January 27, 2023, 5:09pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/4 "2023-01-27T17:09:55Z")

</div>

Thanks so much. I forgot to mention the student’s one request…to start the game when any button is pressed. Any suggestions are appreciated.

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [January 27, 2023, 11:08pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/5 "2023-01-27T23:08:15Z")

</div>

Alright, I fixed the problem (I think)! I just added a true/false variable that asks whether or not the game is started. Here’s the link to the updated game:

> **[Game for good Game for change](https://arcade.makecode.com/S10733-26540-24443-28900)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I hope this helps!

---

<div class="post-metadata">

**Author:** ![SOCKMONSTER12](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sockmonster12/32/7584_2.png) [@SOCKMONSTER12](https://forum.makecode.com/u/SOCKMONSTER12)\
**Post date:** [January 29, 2023, 11:57pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/6 "2023-01-29T23:57:43Z")

</div>

you can also take away the if block to start because the game can’t comprehend it and the trash can’t be placed at 150 because the tilemap isn’t big enough.

---

<div class="post-metadata">

**Author:** ![edillard](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@edillard](https://forum.makecode.com/u/edillard)\
**Post date:** [January 31, 2023, 6:08pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/7 "2023-01-31T18:08:36Z")

</div>

Hi Bruce

- In my experience this happens when you modify a sprite before you declare it.  
You need to use the Create Sprite block (1st block under sprites) - or the Projectile block first.
- Then you can set position, destroy, etc.  
Generally - the error is in OnStart blocks. But if you set a projectile to spawn when you hit a button, or if you have a timer block that spawns a projectile in a certain timeframe - then you have a loopForever block that does something to the projectile you can also run into a problem.

---

<div class="post-metadata">

**Author:** ![BruceSchwa](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@BruceSchwa](https://forum.makecode.com/u/BruceSchwa)\
**Post date:** [February 1, 2023, 7:04pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/8 "2023-02-01T19:04:55Z")

</div>

Awesome. Thank you very much!!!

---

<div class="post-metadata">

**Author:** ![BruceSchwa](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@BruceSchwa](https://forum.makecode.com/u/BruceSchwa)\
**Post date:** [February 1, 2023, 7:04pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/9 "2023-02-01T19:04:57Z")

</div>

Thanks so much!

---

<div class="post-metadata">

**Author:** ![BruceSchwa](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@BruceSchwa](https://forum.makecode.com/u/BruceSchwa)\
**Post date:** [February 1, 2023, 7:04pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/10 "2023-02-01T19:04:59Z")

</div>

Thanks so much!

---

<div class="post-metadata">

**Author:** ![rkennedy2016](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/rkennedy2016/32/14419_2.png) [@rkennedy2016](https://forum.makecode.com/u/rkennedy2016)\
**Post date:** [June 16, 2024, 4:44pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/11 "2024-06-16T16:44:48Z")

</div>

i see that the assert trash\_left and trash\_right was in a forever loop but it was not created untill you press any key look the image below

![help](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/a022945787fb9c54ae1a1b7b23c57ffc51d8f2f4.png)

---

<div class="post-metadata">

**Author:** ![rkennedy2016](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/rkennedy2016/32/14419_2.png) [@rkennedy2016](https://forum.makecode.com/u/rkennedy2016)\
**Post date:** [June 16, 2024, 4:45pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/12 "2024-06-16T16:45:00Z")

</div>

this is whats happerning on start

![help 2](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/8/8a775f3225bffca035be4ab638eea7d82c51166a.png)

this is the problom

---

<div class="post-metadata">

**Author:** ![Noapea](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Noapea](https://forum.makecode.com/u/Noapea)\
**Post date:** [November 25, 2025, 6:12pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/17618/13 "2025-11-25T18:12:41Z")

</div>

You need to create the sprite before doing anything with it hope this helps,ps
