#I fail to understand

1 messages · Page 1 of 1 (latest)

feral terrace
#

So you are getting a null reference to what exactly?

void fern
#

your guess is as good as mine

#

it didn't disclose

#

BUT

feral terrace
#

In the unity console it should point you to a line

void fern
#

I can tell you that the error only comes up when the enemy gets shot

feral terrace
#

Show me the code block for whatever line 18 is?

void fern
#

oh, its pointing at the score value

#

ignore the //is registering false part

feral terrace
#

so yeah in the Start() method, set ScoreManager.Instance.score =0

void fern
#

doesnt that make the score reset every time an enemy spawns?

feral terrace
#

If that is how you have it setup ye

#

Otherwise

void fern
#

I just realized something

#

ScoreManager is a subobject to BulletBoard

#

would that be causing the issue

#

shouldn't it be BulletBoard.ScoreManager.instance.score or something?

feral terrace
#

No idea. Without looking at ALL your code, its hard to tell. But Conceptually the reason you are getting that issue is cause score = null at the time you are trying to += it.

#

So You need to set the score to 0 before you try to add to it

void fern
#

so maybe the Score Manager needs to be set it to 0 on wake?

feral terrace
#

ye

wicked sigil
#

isnt score an int?

void fern
#

actually its already set to 0

wicked sigil
#

int cant be null..

#

its your instance that is null

feral terrace
#

my mistak @wicked sigil is right

#

I'm tired lol

wicked sigil
#

nah some other ppl were saying that the int is null too np

void fern
#

I was about to say

#

Every time I have worked with an unset integer that is serialized or public, it shows a 0

wicked sigil
#

yeah floats and ints are initialized as 0

#

but now you gotta figure out why your instance is null

#

(i suppose)

feral terrace
#

shouldn't your code just be ScoreManager.score = 0'?

#

Or am I missing something

#

I mean score +=

wicked sigil
void fern
#

does the fact that ScoreManager is a SubObject to BulletBoard (which is present in the scene) mean anything?

void fern
#

okay

feral terrace
#

I'm going to chalk this up to me bieng an idiot and tired lol

#

I'm sure the solution is super simple too

void fern
#

No errors come up in the IDE

#

for either .cs file

feral terrace
#

Only in unity

void fern
#

only Unity is complaining

wicked sigil
#

just put Debug.Log("ScoreManager instance exists: " + (ScoreManager.instance != null));
before line 18

feral terrace
#

^^

void fern
#

could I put that on Start instead?

#

because line 18 is only reached if the object gets shot

feral terrace
#

Yeah but that is where unity is pointing

#

Easier to just but it right before to avoid any weirdness

void fern
#

Oh

#

Well i DID just run it on start

#

and it returned false

feral terrace
#

When in doubt Debug.Log out i guess

void fern
#

could this be causing it to delete itself erroneously and making it return false?

feral terrace
#

TBH at this pint I'm outta my league I have no idea

#

I imagine it COULD

wicked sigil
#

make sure you have only 1 ScoreManager in scene

void fern
#

It IS deleting itself

feral terrace
#

At this point I wish there was something like ctor for Debug.Log

wicked sigil
#

wait wtf is even that

feral terrace
#

ctor?

wicked sigil
#

if(instance == null && instance != this)

feral terrace
#

Oh

#

yeah what is that

wicked sigil
#

i think it should be if(instance != null && instance != this)

void fern
#

it supposedly checks for other instances

wicked sigil
#

did you make sure you gave only 1 ScoreManager in scene

void fern
#

this is it

#

whoops

wicked sigil
#

yeah pay attention to what you copy 😆

wicked sigil
#

"Click to open rate"? or Constructor

feral terrace
#

constructor

#

click to open rate?

wicked sigil
#

how would you use a constructor for Debug.Log

#

if you do Debug.Log("ASD", gameObject), it holds a reference to the object