As it stands, your code will create an instance of the engine–which inherits from ShowBase–with every “Object” instance that you create. And, as the error indicates, there may be only one instance of ShowBase per program!
So, I suppose that my question is this: Why is it that you’re creating an instance of the engine with every Object?
But none of that requires that there be a ShowBase instance in the class.
In short: Don’t have a ShowBase instance in the class.
… If I may, perhaps it might help to link you to my “Panda3D Beginner’s Tutorial”–amongst other things it covers one approach to designing the classes for a game, which might prove useful to you in this matter. Here’s a link below, if you’re interested:
You overall game might be aided by the presence of a ShowBase object (although there are other ways). However, depending on your design, your Object class very likely doesn’t require a ShowBase object–or at least, doesn’t require a separate ShowBase object for every Object.
To some degree this depends on quite what you have in mind, but a simple design might look something like this:
class TestEngine(ShowBase):
def __init__(self):
super().__init__()
# The rest of your setup--e.g. "self.disableMouse()"--follows
# here. I've just omitted it for brevity
class Object(NodePath):
def __init__(self, EngineObject, Name, ModelPath, SizeX = 1, SizeY = 1, SizeZ = 1, PosX = 0, PosY = 0, PosZ = 0):
self.model = EngineObject.loader.loadModel(ModelPath)
self.model.setScale(SizeX, SizeY, SizeZ)
self.model.setPos(PosX, PosY, PosZ)
self.model.reparentTo(EngineObject.render)
In this case I’ve chosen to pass a reference to the ShowBase object into the constructor of the Object class as a parameter, giving me access to it without requiring that I make a new one.
That said, personally I prefer to keep a “common” file that stores a reference to the ShowBase object and that other files can then import–I find it a little neater, myself.
Sort of–but there wouldn’t be one made for every Object. There would be just one, and it would be passed in whenever an Object is made. Something like this:
class TestEngine(ShowBase):
def __init__(self):
super().__init__()
# The rest of your setup--e.g. "self.disableMouse()"--follows
# here. I've just omitted it for brevity
anObject = Object(self, "a name", "model.egg")
anotherObject = Object(self, "another name", "model.egg")
# Note that these pass in "self", which here refers to
# the current instance of "TestEngine"
You’d then just start the “TestEngine” as per usual.