Assertion failure when trying to access node from function

The node is as a public SharedPtr

Here is the function:

int getPlayerPos(int comp) {
	Vector3 playerPos = playerNode_->GetWorldPosition();

	if (comp) {
		return round(playerPos.z_ / 6);
	else {
		return round(playerPos.x_ / 6);

The function is called within HandleUpdate(). If you need more code just ask.

playerNode_ is probably empty (null). Make it not null.

Or check whether the playerNode_ is null. If it is, avoid accessing its members and methods.

Also, welcome to the forums! :confetti_ball: :slightly_smiling_face:

I do not believe that the node is null. Running this code within the Start() function causes no problems:

Vector3 playerPos = playerNode_->GetWorldPosition();

Do not believe. Debug.

1 Like

@sherb3t Try adding assert(playerNode_); before you otherwise use the pointer and see if the assertion fails.

Still fails. Thanks for the help.

If the pointer is null the assertion should indeed fail.

How do I check if it’s null. I’m pretty sure it isn’t because I’m using it no problem in the start function…

The pointer is infact null when accessed from the function. When I try and check in the Start() function I get an error with this code:

if (playerNode_.Null()) {
std::cout << “yes its null \n”;

The error is “expression must have a class type”.