Draw Object in Front of Everything Else

How do you get an object to be rendered in front of everything else in a scene in the game engine? I’ve looked through material and object properties, but I didn’t find anything that worked. I basically need to have the same functionality that the X-Ray property has in the objects tab (but that doesn’t work in the game engine).

The easiest way would be to use an overlay scene. If I recall, the Scene logic brick allows for this functionality. If you still need the object to ‘exist in 3D space’ like the rest of the game objects, then you can use Python to sync the position of the overlay scene object with an invisible game scene object.

Stick it in an overlay scene is the easy way.

–edit–
you beat me…

That would make things pretty difficult with the setup I’m trying to use. I’m basically giving the player x-ray vision, so the objects could basically be anything from enemies to power-ups. Since these things are already running logic that requires them to be in the same scene as the player, putting them on an overlay scene would cause quite a few problems if I’m not mistaken.

Z-offset works in render mode (enable Z transparency, and then under options change the Z-sort value), but doesn’t in multi-texture. It might in GLSL, I haven’t tried.

That works. Giving it a positive Z Offset in GLSL did the trick. I guess I can just use an action with keyframes on Z Offset to switch the object between x-ray and non x-ray modes. Thanks guys.

Ok, so it turns out there’s still a problem. The objects show up fine through other objects except when the camera is directly in front of the object’s face. It’s kind of hard to explain, so here’s a .blend that shows what happens

Draw.blend (425 KB)

WASD moves the camera. Notice that the cube is visible through the wall except when the camera is directly in front of the cube (the starting position). Any ideas, or is this just a bug? I’m using Blender 2.63 btw.

The camera frustum ends slightly before the camera. You can adjust it with the Clip Start parameter of the camera.

Just a guess

Sorry, but that’s not the case. Even if it was, the wall would be out of the camera frustum before the cube

Edit: Oh, and by “directly in front of” I mean just the direction, not that the cube is right up next to the camera.

Edit2: Another note, if you change the camera to orthographic, the effect is more noticeable. It’s actually just the front face of the cube that isn’t visible, and you can still see the sides through the wall.

Another guess:

If I interpret the above solution you move the mesh forward via GLSL vertex shader.

That means the mesh itself stays where it is. The mesh might be sees as out of camera frustum by the BGE. In that case the shader has no mesh to move towards the camera which makes it invisible. See Objects disappearing at edge of camera.

As I wrote, this is just another guess.

Monster

PS: I can’t test your file. I do not have glsl at this PC.

Again, I still don’t think that’s the problem. If the wall isn’t between the camera and the cube, I can move the camera right up next to the cube and it’s still visible. Also, adjusting the amount of Z Offset doesn’t seem to have any effect (except when it’s too low and the cube ceases to be visible through the wall).

One interesting side note: Transparency doesn’t have to been enabled to use Z Offset. Even though the setting is greyed-out, you can still adjust it, and it still seems to have the same effect.

Edit: I also tried making the wall partially transparent. This causes the front face of the cube to become visible, but it’s darker than the other faces because it’s still being drawn behind the wall while the other faces are drawn in front.

How do you change the z-offset?

^ You can change the Z-Offset in the material settings.

Thanks SolarLune.