Objects randomly disappear when running the game multiple times without any changes

Hello,

I’m new to Defold and I’m experiencing a strange issue.

I have a very simple project with:

  • A background sprite
  • A player Game Object with a Sprite component and a movement script
  • A star Game Object with a Sprite component using an Atlas animation

The project builds and runs successfully, and there are no errors or warnings in the console.

The problem is that the objects appear inconsistently between runs, even when I don’t change any code or assets.

For example:

  1. Run the game → only the player appears.
  2. Close the game.
  3. Run again without making any changes → only the star appears.
  4. Close the game.
  5. Run again without making any changes → neither object appears.
  6. After several runs, sometimes both objects appear correctly.

I also tried:

  • Project → Clean Build
  • Closing and reopening Defold
  • Verifying that there are no errors in the console
  • Confirming that both Game Objects are present in the main collection

After a Clean Build the issue still persists. In one test only the star was visible while the player disappeared.

Console output only shows normal startup messages:

INFO:ENGINE: Defold Engine 1.12.4
INFO:ENGINE: Loading data from: build/default
INFO:ENGINE: Initialised sound device 'default'

No errors or warnings are reported.

Has anyone seen this behavior before? Are there any known causes that could make Game Objects or Sprites randomly appear/disappear between runs?

To make troubleshooting easier, I’ve attached several screenshots and a link to the project’s GitHub repository:

GitHub repository:

The issue can be reproduced by running the project multiple times without making any changes. Any guidance would be greatly appreciated. Thanks!



It is probably because of a z-fighting issue. I bet all your game objects have the same Z value, so they are fighting each other. You might try changing them a little, something like:

  • Background: Z = 0.0
  • Stars: Z = 0.1
  • Ship: Z = 0.2

This should help prevent z-fighting.

10 Likes

Thank you very much! That was exactly the issue. After adjusting the Z values, everything works correctly now.

Solved, thanks!

3 Likes