Texture Render problem

I found this project example for Texture render : Tutorial

I created a new Layer in settings, which I applied in my Camera

After that, I copied scripts from the project sample, and on the property set the same string name as my layer
ApplyTexture script is on my UI element, which needs to display everything my camera is rendering
But I have 2 errors, and I can’t figure it out what’s the problem
Does anyway knows how can I fix this , on 2. error when i apply material , it’s not working again

Hi @Dava,

What’s the exact code that is failing in your scripts, on those lines?

I’d say in both cases try and debug if everything executes and references the expected objects.

  • In the first case if this.layerName is the expected one, and a pc.Layer reference is returned.
  • In the second case if the model is loaded (mesh instances are available) and references a material.

Your best friend here is the debugger, you can either set a breakpoint or use the debugger; statement just before your code executes.

There is something in the console, but I don’t really understand any of this stuff

That’s a warning, that’s unrelated. On line 19 the layer name is correct.

Now try to debug the next line, var layer.

You can study a tutorial online on how to use the debugger, it’s quite important to resolve this kind of errors.

1 Like

I figure it out, I didn’t set sublayer :sweat_smile:

The only problem left is, image is not showing anything
My script is on the sprite, set material instead of texture, but it’s still transparent

If anyone has time, I would really appreciate it if you take a look at this project
Sprite is under 2D Canvas “Main 3D Studio”

Instead of applying it to the material, it’s better to assign it to the texture of the element:

    this.elementEntity.element.texture = colorBuffer;

Example of what looks like you are trying to do here:


I forked the project and doing some testing.
Is it possible to make the background transparent from the world, like an only cube to be rendered, not the blue background from the world camera
Test project: PlayCanvas 3D HTML5 Game Engine

Yes, you can. You have to make sure that the camera with the render target has a fully transparent clear colour.

Also need to make sure that the render texture has an alpha channel.

Fixed version: https://playcanvas.com/editor/scene/1245865

1 Like