#NullReferenceException

1 messages · Page 1 of 1 (latest)

visual fractal
#

Hello, guys! I got a reference issue but I am not sure why? I have tried to add some debug.log statements to figure it out it says that the issue persists somewhere in my PlayerController script at the lines it says in console. Is someone available to help figure it out?

#

I will be off for a while. So, I am going to send all the information needed for that issue and after that we will catch it up when we left it.

sullen fable
#

objectPooling is null so it hasn't been assigned in the inspector

visual fractal
#

Yeah

#

The problem is that I have a parent game object for object pooling and child game objects

#

Here

#

The parent is empty on inspector

visual fractal
sullen fable
#

no, it hasn't been assigned in the player controller

visual fractal
#

Yes I see it before I had it as an instance

#

I mean I did something like

#

public static ObjectPooling Instance

#

I thought if maybe the problem was with that and change iut

#

it

#

So, now yeah I have to assign it inside player controoler

#

But don't know which object to assign?

sullen fable
#

The one that you want it to use

visual fractal
#

The issues persist it says at these lines

sullen fable
#

Show the player controller's inspector

swift verge
#

Could you show RoundManager script?

visual fractal
#

Yes

visual fractal
swift verge
visual fractal
#

No problem I am going to send all of my scripts at the top so you can see them. I have sent already 2 of them

sullen fable
#

There's no field in the inspector for the object pooling?

swift verge
#

Anyway, where are you setting/initializing objectPooling?

#

ugh i read the wrong line again

visual fractal
sullen fable
#

why

visual fractal
#

Because thats how I had it before

sullen fable
#

Before, when it also didn't work?

visual fractal
#

I was just wondering if I am going to change that and take reference what will happen

#

Yes

swift verge
#

in your playerController script you say that objectpooling.cs exists but not which one exists

visual fractal
#

IT doesn't work for both of them

sullen fable
#

Put it back the way it was and assign the reference in the inspector

visual fractal
#

Yeah but in player controller which object to assign there thats what I dont understand

#

I have collision, gemparticle and logs

#

Those are childs of object pooling game object

swift verge
#

Okay well, where is objectPooling.cs? is it attached to an object or is somewhere else?

visual fractal
sullen fable
#

Well which one of them do you want to use?

visual fractal
#

It is here inside my childs

#

Object pooling cs

#

Parent is empty in inspector

swift verge
#

So logsPooling, GemParticelPooling and collisionParticle pooling all have the ObjectPooling.cs Script on them?

visual fractal
#

Can I make like different classes for each of them

sullen fable
#

I assume you want to use gem particle pooling when the bird collides with a gem, right?

visual fractal
#

yes

sullen fable
#

and log pooling when it collides with a log?

visual fractal
#

of course

#

collision when player collides with the log

#

collisionParticle

sullen fable
#

Then you obviously can't use one field to store all of them

visual fractal
#

logs is for instantiating this game object

#

logsPooling I mean

swift verge
# visual fractal

Okay well your playerController script knows that ObjectPooling.cs exists but it doesnt know that all these objects exists, you need to get a reference to ObjectPooling.cs on these objects.

sullen fable
#
public ObjectPooling gemObjectPooling;
public ObjectPooling logObjectPooling;
public ObjectPooling collisionObjectPooling;
#

then use whichever variable you need in the code

swift verge
#

Yes ^

visual fractal
swift verge
#

yup

sullen fable
#

that's where you use the variables, right?

visual fractal
#

I dont think so because OP.cs is responsible for that like I said before I have OP.cs inside my child game objects

swift verge
visual fractal
#

Yeah that does nothing and I was wondering

#

I have to get the refernce

swift verge
#

yes

#

Nitku just showed you how to get the reference

visual fractal
#

Ok I am going to make it on playe controller

sullen fable
#

How the objects are arranged in the hierarchy has absolutely nothing to do with it

visual fractal
#

You mean it doesn't matter where i am going to use those variables?

swift verge
sullen fable
#

No, I mean that their arrangement in the hierarchy has nothing to do with it

visual fractal
#

Guys I didn't want you to solve it for me but anyway XD

sullen fable
#

You're lacking skills in very basic Unity/C# concepts so it's hard to do otherwise

swift verge
#

Nitku did also tell you what you needed to do earlier but you just like didnt

visual fractal
#

I know how to set references and all of that I am using unity 1 year already I was just confused where I have to use that references cuz I have OP.cs and PC.cs

sullen fable
#

If you don't know that you have to set the values of variables in the same script where you use them, that's a very basic issue

visual fractal
#

I am working on that game with a guy by the way he is a collaborator and trying to help me with the game. This part was made by him, so I wasn't sure what he did here XD.

#

He just left for me some issues to handle myself

swift verge
#

Ahh that makes sense

sullen fable
#

These aren't the kind of things that would be different depending on who wrote the code

visual fractal
#

Guys I have to leave somewhere now it is a need, so I will come back and we will continue for now I have to close it. Thanks!

visual fractal
#

Hello, guys! Are you there?

#

Before closing the thread I have a very small issue to solve.

swift verge
#

@visual fractal the issue?

visual fractal
# swift verge <@827977889978384396> the issue?

So, what I want to do is to actually enable and disable my options ui elements in main menu scene. In main menu I have a button which says Options. So, what I done before was to load the options scene when clicking that button. Now, I got confused of how to make my options scene enable and disable I dont want to load a new scene.

swift verge
#

Just set it unactive

swift verge
#

@visual fractal any luck?

visual fractal