[SOLVED] How to make text be able to be seen through objects

Hello, all. I am wondering if its possible to make text be able to be seen through objects. I would like this for only some text, for quest NPC names. Is this possible? Thanks.

I’m not sure you can do this with the official API. But this is how I hacked it to work.

  1. Create a new Layer called Labels.

  2. Assign this script to your scene’s root:

    var ClearDepth = pc.createScript('clearDepth');
    
    // initialize code called once per entity
    ClearDepth.prototype.initialize = function() {
        const layer = this.app.scene.layers.getLayerByName('Labels');
        layer.clearDepthBuffer = true;
    };
    
  3. Create a text element entity.

  4. Set the text element to render to the Labels layer.

  5. Assign this script to your text element that appears above your NPC:

    var DepthTest = pc.createScript('depthTest');
    
    // initialize code called once per entity
    DepthTest.prototype.initialize = function() {
        // Warning: this is not public API
        this.entity.element._text._material.depthTest = false;
    };
    

Thanks for the code. For some reason, it is not finding the layer, even though I have defined it.



You only created the layers, but not added them. You should add them, so they are actually used:

1 Like

Thanks a lot for clearing that up. It works great now! Is there a way to add and take off entities from layers in code?

Yes, you can search the forum, there are a few topics about it. For example

1 Like

Thanks, I definitely will! Thanks @will and @LeXXik for helping me with this!

1 Like