How does a class in Python work in UPBGE?

I know modules, but what the heck is a class, and how does it work? I wonder how would I utilise a class in UPBGE’s python system? Like scripting weapons or something else. Ive never done a class before. What are the advantages/disadvantages of classes?

Classes are useful if you have behaviors that all subclasses will inherit.

We can use components system in 3x to register a class, and no longer need to mutate a base class.

@mysticfall helped write the new version I believe.

Can you give me an example of what a class does?

A class is simply said just a structure with a bunch of methods which are “aware” of the class by refereing to it by self or this… a sub class would inherit all the methods from it’s super class so it automatically can do what those does but additionally can overwrite the behaviour to it’s own needs… also variables can be made invisible to the outside (capsulation)…

For example every Node in for example the shader editor (or geometry nodes editor or…) has to be moved, resized, enabled, renamed etc… so someone doesn’t have to write this for every new node type… but just have to say: this is a new Node type (and so inherited from Node…).

So it’s a tool to make code more maintanable / managable… (but also can drive app programmers crazy if badly designed)

1 Like