DirectButton doesn't show state dependent geometry.

I need some help here. I wan’t to create a DirectButton instance with my own geometry.

I have an egg file, holding information for four geometries specifying for each of the states. In my code I load the egg file using

geometry = loader.loadModel (<<egg file>>)
button = DirectButton (relief=None, geom=geometry)

When I view the output of ls() it shows me I have loaded a model with a single SwitchNode and four child GeomNode

SwitchNode buttonNewGame [class command]
  GeomNode buttonNewGame_normal (1 geoms: TextureAttrib TransparencyAttrib)
  GeomNode buttonNewGame_clicked (1 geoms: TextureAttrib TransparencyAttrib)
  GeomNode buttonNewGame_highlight (1 geoms: TextureAttrib TransparencyAttrib)
  GeomNode buttonNewGame_disabled (1 geoms: TextureAttrib TransparencyAttrib)

However, when the button is showed, it only displays the first geometry and there is no visible sign of state dependent selection of geometry.

Any ideas???

Use it something like this instead:

b = DirectButton(geom = (geometry.find('**/buttonNewGame_normal'),


Solved it. It turns out that DirectButton explicitly needs a tuple of four NodePaths to create state-dependent switching. However, I assumed,
since the showed it to me, that if I specified a SwitchNode in the geom parameter it would automatically see the state-dependent nodes and then act accordingly. Turns out I was wrong. By explicitly using the .find method and creating a tuple it started to work how I wanted it to work.

However, it triggers me why it is not possible to drop a switchnode in the DirectButton geom parameter. I think this is what you really want. Then the switch behaviour simply becomes part of the .egg resource file instead of the code. Perhaps a new feature for upcoming version??

Anyway, thx. for the quick response.

Feel free to make a patch. It’s python code, so it probably wouldn’t be hard to add this feature.