Draw order of factory-generated objects in relation to existing gui objects (SOLVED)

Hi,

My friend and I are working on a game. We have a space background as a node in a gui, and we built a ship factory to generate the player’s ship. For some reason, the ship is being drawn underneath the space background, and we can’t figure out why. When I move the space background over, I can see the ship, but if the two overlap, the background is drawn on top. We’ve tried using layers and putting a z value (the 3rd number in the positions) but there’s no change. Can anyone give us some ideas for how to debug/fix this? Is it possible to specify the factory-generated object to draw on top of the others?

Thanks,
-Andrew

By default, all gui nodes are drawn after all sprites (I’m assuming your ship uses a sprite). Is there a reason why your background is a gui node? The easiest way to fix your problem is to make the background a sprite and put it at a lower Z position than your ship. If you want it to stay in the same spot relative to the camera, you can child it to the same game object as your camera.

Alternatively, you can modify your render script (manual here) to make a group of gui nodes that draw before sprites. You would need to:

  1. Create a new render predicate for your background gui (in the init function).
  2. In update, before setting the view, projection, and render states for sprite rendering, draw your background gui predicate.
  3. Copy the built-in gui material (with it’s vertex and fragment shaders), switch the tag of the material to the name of your background gui predicate, and set your gui to use this material.

. . . and hope I didn’t forget a step. :slight_smile: . . .

1 Like

Ok, well, that is what we ended up doing, so I guess we’re on the right track.

It just seemed like the gui was a nice spot for the background because it was visible when you opened the gui, so it was a visual indication of what was going on. Presumably if we were to add other objects into the space level/map then it would function a bit like a map editor, where you can visually see the level. Anyhow, we will stick with doing it as a sprite, seems easier than modifying the render script. Thanks for the info!

This doesn’t work. My sprites are still created under the gui nodes

Did you edit your render script too? Did you assign the new material to the GUI you want behind?

2 Likes