How do you approach OO Design and OO Programming with GameObject and Components in UPBGE?

How do you approach OOD with GameObject and Components?

I’m trying to better understand things in a deeper sense. I usually have something like:

class Player(KX_GameObject)

and then I have several

class Movement(KX_PythonComponent)
class UI(KX_PythonComponent)
class Animations(KX_PythonComponent)

Is this a sound way of doing it? I feel like I’ve been learning a ton about OOD, OOA, OOP and I’m struggling to implement it in my code using Components and GameObjects and Properties inside of UPBGE.

I want to better understand the relationship between a GameObject and a PythonComponent. When I create a Cube and create a KX_GameObject with it and also a KX_PythonComponent. I notice that the KX_GameObject has access to the Component class through a self.components list. Giving you access to all the attributes and methods inside your Component Classes associated with that same object in your scene.

I also just realized that in the Game Object there is no self.object like in the Component Classes. But in KX_GameObject self is the object. And something cool is all the methods I create inside of my KX_GameObject class are passed down to my Component classes like Inheritance.

I want to design a game using clean design and OO principles. I understand this question is very very particular to UPBGE but I would still love feedback on OO principles you have used in Game Development. Thanks


  • Hopefully this helps someone in the future. I found this in the documentation!!!! It was there the whole time, and it's pretty amazing. (to me) It basically answers all my questions about the relationship between GameObjects and Components in UPBGE.

    Why don't I read this stuff earlier... :man_facepalming: