Test for empty nodepath

In Python, attempts to use any NodePath derivative as a boolean results in the error stating that this behavior is depreciated.

However, I can’t find any examples of how one is supposed to test for a NodePath’s existence. What’s the proper way for checking if a NodePath exists?

If bool(yourNodePath) or yourNodePath.isEmpty() (same thing) evaluate to false, you can call yourNodePath.getErrorType() to find out why it’s empty. It can be one of ETOk, ETNotFound, ETRemoved or ETFail.

The short answer is, the unambiguous way to test a NodePath return value is:

if not nodePath.isEmpty():
    # nodePath is valid
else:
    # nodePath is empty (failure case)

In the future, or if you put “empty-node-path future” in your Config.prc file, then you may also write the above test like this:

if nodePath:
    # nodePath is valid
else:
    # nodePath is empty (failure case)

David

Well, that makes sense, then. Thanks for the help you two!

The error type is especially useful info.