Environment model does not render if loaded from function in separate file

Hi, extremely amateur programmer here.
After being able to get a program to run successfully entirely in main.py, I wanted to move most of the code to another file which I could import later, so I could boot into a menu, and then the main game.
However, Environment.egg.pz does not render after I moved the code, and I am instead treated to a blank screen.
I can confirm that the model is loaded and attached to render with render.ls(). I have also confirmed it renders when loaded from main.py.


from direct.showbase.ShowBase import ShowBase
from gamecode.game.single import *

class gameBase(ShowBase):
    def __init__(self):
        noServer(self, "environment")

app = gameBase()


def noServer(self, map):
        #enables physics
        #Load the enviroment
        self.scene = self.loader.loadModel(map)
        #self.scene.setPos(-12, 250, -25)

        #Set up the player
        Player = self.loader.loadModel("testboxes.bam")

        #A bunch of stuff commented out for testing

What I see when I run main.py:

Ah, I think that I see the problem: You’ve reparented the camera to “Player”–but “Player” doesn’t appear to be reparented into the scene-graph (i.e. to render or any node below it).

As a result, the camera isn’t connected to render, and thus doesn’t have access for rendering to anything that is connected to render; it only has access to the player. And the player is presumably at the same location as the camera, and thus not in view.

1 Like