Help with Camera Render to Texture

I followed a tutorial to create a rearview camera and it works well but with one weird issue. If the camera is in an overlay scene, it only works after I have run the game once. So I open Blender and run the game = doesn’t work. Run the game again (without closing Blender) and it works fine.

I moved the plane with the rendered texture to the main scene and it works fine on the first run, so it is only an issue with the overlay scene. Unfortunately I REALLY need it on the overlay.

Here are the 2 scripts I use.

Initialize the rearview:

def RearviewInit(cont):
    own = cont.owner
    for i in g.getSceneList():
        if == "Scene":
            scene = i
    cam = scene.objects["RearviewCam"]

    matID = texture.materialID(own, "MARender")
    renderToTexture = texture.Texture(own, matID)
    renderToTexture.source = texture.ImageRender(scene,cam)
    own["RenderToTexture"] = renderToTexture

Refresh the texture (runs every frame)

def RearviewTex(cont):
    own = cont.owner

Anyone know why that won’t run the first time but every subsequent time it runs fine?

I solved the problem. I needed to delay not 1 but 2 logic frames before initializing. Something must not have been loaded.

Also, for some reason I can’t set the thread to solved so if someone wants to do that for me that would be great. :slight_smile: Thanks!

Edit your first post and set the prefix to [SOLVED] :slight_smile: