Disappearing Child Nodes

I am new to Panda3D development and although most of it has been straight forward and enjoyable I am currently stuck on trying to fix a specific bug.

The application displays a wall with paintings on it.
However when the texture of the wall is changed the paintings disappear and I cannot determine why.

The following nodes are displayed:

#wall: render/mainNode/room_2.egg/-PandaNode/Room/wall_back/backwall
#painting (child): render/mainNode/room_2.egg/-PandaNode/Room/wall_back/backwall/painting_22.egg
#painting (child): render/mainNode/room_2.egg/-PandaNode/Room/wall_back/backwall/painting_12.egg

The problem occurs immediately after the setTexture() call.

wall = self.room.find('**/backwall')
texture = loader.loadTexture('wallcolors/'+str(roomColor)+'.jpg')
wall.setTexture(texture, 1)

Any help would be greatly appreciated.
Thank you.

The “1” override value to setTexture will tell it to override any textures on child nodes, so it will override the textures on the paintings.

Thank you!
This helps explain a lot.

Now I am attempting to find a way to change the texture of the parent without effecting the children.
I am going to capture the children’s texture before setting the parent’s texture and re-apply the children’s texture after modifying the parent.
I realize that from a programmatic perspective this is probably the least efficient way to address the problem.

Are there any other ways to address the issue more efficiently?

Thanks in advance.

Nor will that even work, since when you reapply the textures on the children, they will still be overridden by the setTexture(,1) on the parent. If you wanted to do this approach, you could apply the textures on the children with a setTexture(,2) or some higher number.

Or you could use a less-intensive approach and, rather than parenting the paintings directly to the wall, instead parent them both to a common node. Now you can setTexture() on the wall without affecting the paintings.


I was able to create a work around.
Before setting the texture of the wall a list is created which represents all of the paintings.
Each item in the list contains the NodePath to the painting and its texture.
Then the texture of the wall is set.
Then the list of paintings is used to re-apply the individual textures to each.

paintingList = []
for painting in self.room.findAllMatches("**/painting*"):
     paintingList.append([painting, painting.findTexture('*')])

wall.setTexture(wall_texture, 1)

for painting in paintingList:

I don’t like the inefficiency of looping over all of the paintings twice, but it does produce the desired effect.

David, next I want to try what you suggested and set the textures of the paintings at a higher level initially and see if that allows me to remove the inefficient code above.
Thanks for the reply.

Note that the order in which you call setTexture() means nothing. Only the node structure you create (and the override values) controls which texture is visible.

You can loop over your paintings once, and call setTexture() on each of them only once at startup. Then when you change the wall texture, you can call setTexture() on the wall. You don’t have to do the paintings again afterward.