Personal Help: Render To Texture failure in Standalone Player

I have a game. The game has a scope. the scope uses rendertotexture
If I play the game on the current scene with the scope, render to texture will work
If I play the game from a menu scene, then render to texture doesn’t work…

why is this? I can give an example file if needed

if its a overlay, the camera needs to be on the map scene,

not the overlay.

Did you pack the Python script in the blend or put it correctly next to the executable?

Yes, example file’s needed.

Nope, I’ll just post the full game…too much effort to make the file as small as possible

Play the game in standalone. The scope doesn’t work if you start from the menu, but will if you start from the game scene…why is that?


Okay, I was going to check this out, but on trying the game, I’m getting a lot of "Warning, sensor “ifPICKEDxm8” has lost a link to a controller (link 2 of 2) from object “XM8 T.003”

possible causes are partially appended objects or an error reading the file,logic may be incorrect"

in the console. Tried to make the file simpler myself, but I don’t know - looks like you didn’t package all of the files (i.e. some things are linked or appended?). I’m getting some weird logic execution on the Scope plane itself as well, as if it’s not really executing the Python script…? Making the file as small as possible might actually be needed here.

EDIT: I appended the scope plane to a new blend file and made a new camera named “ScopeSee”. The texture was replaced correctly in both Blender and the standalone player. This leads me to think there might be something wrong with your blend file, perhaps those errors (that I’ve never seen before) from above. Always check the console for errors, even if you’re not using Python (though you are in this case).

Hmmm that’s really strange. I never get any of those messages. Everything works fine for me. I’m using 2…69 to make the game, if that has anything to do with the errors, probably not though

Yeah, if you/I play the game from the game scene (no menu) then the scope works fine. But if I use stand alone or from the menu, then something goes wrong and the texture isn’t replaced at all
I’ll re-upload the file since I made some small changes since. Hopefully this one will work

Oh, and the menu and the game weren’t in the same file together. I just used the game and appended the whole menu into the game…

It’s the same thing with separate files too. If I use the menu to play the game (via play from file in “Game” Actuator) then it won’t work. but if I play the game directly from file then it all works…

I realize what you’re saying once I opened up console…I should also tell you that the XM8 was appended from another game I made…that might be the reason, as there is absolutely nothing in any of the XM8 objects’s the simplified version that demonstrates the same problem

Ahh All I did was delete all of the Enemy 1’s and then that solved it. I don’t know why, but it works. I’ll just rebuild the enemy…Sigh
What was the problem though? I know a solution, but what caused it?

more then 1 link to the same file?

Nope, just use the #6 one
The solution I came up with was to just delete all the E1 and it’s parts, but why does that work and where’s the problem?

Okay, it’s a different matter entirely - it’s a bug. It’s kinda complex.

The first time you load the blend file, if you press play and the replacing object isn’t onscreen, the material never updates. Every other time, it will.

In the standalone player, it’s basically always “the first time”, so unless the replacing object is onscreen when the game begins, the material will never update.

You can slide around this by printing something out about the source’s image, like:

import bge

controller = bge.logic.getCurrentController()
obj = controller.owner

if "RenderToTexture" in obj:

    print(id(obj['RenderToTexture'].source.image)) # < Prints out the Python ID of the image; doesn't really do anything, but somehow forces the engine to "remember" the texture and update it correctly.
    scene = bge.logic.getCurrentScene()
    objList = scene.objects

    matID = bge.texture.materialID(obj, "MAMaterial")
    renderToTexture = bge.texture.Texture(obj, matID)

    renderToTexture.source = bge.texture.ImageRender(scene, objList['RenderCam'])

    obj["RenderToTexture"] = renderToTexture

Printing things every frame slows stuff down, so if you really want to just force ahead to make it work, then I would suggest adding a timer to make sure this doesn’t happen for too long - just long enough to “kickstart” the replacement process.

EDIT: To reiterate, I wouldn’t recommend using the hack above as printing things out can slow down the game. If you need the hack, add a timer to ensure the printing line only happens for a little while.

In any case, I’ve uploaded a bug report here.

EDIT 2: As a final side-note, I appreciate that you simplified your blend file, and I thank you for that. However, you could have simplified it a lot more - almost 100% of it was unnecessary. The point isn’t to remove an arbitrary amount, but rather to remove all of the extraneous elements - all of the stuff that has nothing to do with the bug. So, keep hacking away at the blend file until one more object removal gets rid of the bug, or until it’s just the bugged object itself, etc. Try to make it as simple as possible.

Again, thanks for the simplification, though.