"unresolved reference" for many variables in PyCharm and VSCode

Common examples i encountered are render, camera and loader. How to set up the IDE correctly? I like Panda3d so far, but It is quite hard to learn a new engine when the autocomplete does not work.


This is because loader and render (along with some others) are automatically set by Panda3D (by ShowBase instance, to be more precise) as global variables. PyCharm doesn’t know about this.
But in fact they are members of the ShowBase instance, so you can access them as

base = ShowBase()

and so on. Hope this was helpful.

Yes, thank you very much for the quick answer! This helps a lot.
So the base = ShowBase() does not create a new instance, but just grabs the current one?

edit: I guess you meant i could do that just to access the variables, and delete those lines later.
I am also quite new to python, as you probably understood.

I honestly don’t know whether (apparently) constructing a new “ShowBase” object as shown above does in some way fetch a global pointer; I’d suggest confirming that before using the above method.

That said, if you’re already creating a “ShowBase” object–such as if your main game-class derives from ShowBase–then you should be able to access those global variables through that.

For example, if your game-class inherits from ShowBase, then within that game-class you should be able to simply access the variables via the ubiquitous “self” reference. Something like this:

class MyGame(ShowBase):
    def __init__(self):
    def someMethod(self, someParameter):
        model = self.loader.loadModel("cat") 
        # Note the use of "self" in the lines above

game = MyGame()

Similarly, anywhere that has access to an object of that ShowBase-derived class should be able to access those global variables through that object. Like this, for example:

class OtherClass():
    def __init__(self):
        self.someData = 0

    def doSomething(self, game):
        model = game.loader.loadModel("cat") 
        # Note the use of "game" in the lines above

class MyGame(ShowBase):
    def __init__(self):

        self.otherObj = OtherClass()

game = MyGame()

Having these global variables appear undefined in PyCharm is indeed a bit of a nuisance. While one can work around the issue indeed, it would be helpful if there were some way to get it to recognise the variables produced by ShowBase! If there is such a way, then I too am interested to know of it!

[edit] For the most part, I just ignore PyCharm’s highlighting of these global variables. The highlighting is a minor nuisance, but it doesn’t seem to cause any issues.

1 Like

Thank you guys for very helpful advice. The first solution from maxxim actually caused a crash, because panda3d seems to only allow one instance of ShowBase.

Using the self keyword seems to work perfectly for my needs. Also thank you for your excellent tutorial on github, Thaumaturge. I am working my way through it at this very moment!

1 Like

The tutorial is my pleasure! I’m glad if it’s proving useful. :slight_smile:

Sorry if I misguided you, I didn’t know you inherit from ShowBase. I myself don’t, so I gave the code I am usually using.

You can use

import builtins

and then use


instead of