#null instance for an important variable, whats the solution?

1 messages · Page 1 of 1 (latest)

chrome mason
#

so, i am currently having a minor problem that is causing crashes with every time i use it.

I have managed to develop the rolling mechanic, and make it work amazingly, but now im stuck with the ability to be invincible whilst rolling.

What i have, at the moment, is a game manager.
when the character goes to roll, it asks the game manager if it is on cooldown or not. If its not, the character continues with the roll action.

when i have the Harm zone (a scene that i add to enemies to make them and/or their attacks dodgable and do the same method when i attatch the scene to an enemy, it seems to have a problem going to the game manager and asking if the character is currently invincible or not.

this means that every time i roll into the enemy, invincible or not, it returns with null and doesnt work.

"Attempt to call function 'is_invincible' in base 'null instance' on a null instance"

i have added the code that apparently is affecting the problem, the tree for the main game, and the tree of the enemy (containing the harmer, which holds the script mentioned)

#

null instance for an important variable, whats the solution?

hollow forum
#

I recommend setting up your game_manager script as a global autoload script in the project settings. This will give you a global class GameManager that you can access instead

#

An issue might still lie in your game_manager script, but that will resolve the error I'm seeing in your picture

chrome mason
#

ill try that-
just a preemptive question, how do i reference a global class in a script?

hollow forum
#

When you set up the autoload, you choose the name. Based on your file name, it will default to GameManager (case sensitive)

chrome mason
#

sick 👍

#

ill get back to you if it dont fuk up

#

do i still need the game manager node in my main game or should i get rid of it?

hollow forum
#

Nope you can get rid of it and it's references

chrome mason
#

ok! so, if i needed to reference it in a script, do i just put it as GameManager and it should work?

hollow forum
#

Yessir!

#

if you have a player variable in game_manager.gd, you can call GameManager.player in any script any time to access that object

#

without declaring anything else first

chrome mason
#

it worked like a charm! thank you so much!