#Null Reference

1 messages · Page 1 of 1 (latest)

glacial panther
#

Could you post the relevant code?

craggy crow
#

cool

glacial panther
#

So depending on how much code it is pbb in a gdl paste

craggy crow
#

its a whole script lol

#

but if you think only the main part then i can try to put that

#
    public void OnPointerDownEvent()
    {
        Debug.Log("did you see me 5");
        buildFishUIController.ShowFishInformation(clownFishSO);
    }
    
    public void AddEvent(GameObject Go)
    {
        EventTrigger trigger = Go.GetComponent<EventTrigger>();
        Debug.Log("did you see me 1");
        EventTrigger.Entry entry = new EventTrigger.Entry();
        Debug.Log("did you see me 2");
        entry.eventID = EventTriggerType.PointerDown;
        Debug.Log("did you see me 3");
        entry.callback.AddListener((data) => { OnPointerDownEvent(); });
        Debug.Log("did you see me 4");
        trigger.triggers.Add(entry);
    }

#

did you want to see the code for the buildFishUIController.ShowFishInformation?

glacial panther
#

The whole script

#

Quite literally ctrl+A ctrl+C ctrl+V it

#

Please do throw it in a paste site though

craggy crow
#

wait didnt look like it is saved let me see

glacial panther
#

Yup you just threw an empty paste site at me lol

craggy crow
#

dont i just paste it and then save it then send u the link?

glacial panther
#

Yes, but you didn't save it

#

The previous time that is

craggy crow
#

yeah its not working it seems

#

i click saved on the top left

#

ill try a diff site

glacial panther
craggy crow
#

oh thats werid

glacial panther
#

It's literally that simple

#

I don't know what you're doing

#

If you press the save button the URL will change

#

You can copy that URL and paste it here

#

otherwise just use GDLpaste

craggy crow
#

i think it might be too long, because when i just type a few lines it works

#

that one works

glacial panther
#

Great

#

Mind sharing buildFishUIController as well?

#

(In a new paste)

craggy crow
#

k

glacial panther
#

Could you tell me what you want your code to do exactly?

#

By the way, you shouldn't need .ToString() in an interpolated string

craggy crow
#

basicallly go to the store, then when a user buys the fish, it instantiate the fish and then the code that I was working on, i want the event trigger to give the fish the UI that display the stats

glacial panther
#

Do you use buttons?

craggy crow
glacial panther
#

For buying

craggy crow
#

yeah

glacial panther
#

Did you use a tutorial for this?

craggy crow
#

yes i did

glacial panther
#

Mind sharing it?

craggy crow
#

but it only gives the basics

glacial panther
#

Which is?

craggy crow
#

it stopped and I added on

glacial panther
#

The event thingy, is that your doing or the tutorial

craggy crow
#

the store works fine

#

thats my doing

glacial panther
#

Alrighty

craggy crow
#

the event is to give the instantiate fish a dashboard so when a user clicks on it, it displays the stats of the fish. I am trying to assign the fish this ability right off the back, after a user purchase the fish

glacial panther
#

I'd use the onClick event

#

Instead of doing OnPointerDown

craggy crow
#

i can do that part, just not sure if it will work on mobile?

#

didnt get a chance to test it yet, but I can try later

glacial panther
#

I cannot help you there

#

I've not made a mobile game

craggy crow
#

oh no worries, i can work with that

glacial panther
#

So I'm fully in the dark of that

craggy crow
#

all good

glacial panther
craggy crow
#

yeah i agree, i tested before

glacial panther
craggy crow
#

atm, it doesnt matter if you think about it

glacial panther
#

Well I don't know that

#

Depends on your needs

craggy crow
#

so the button isnt an issue, the issue is that I am not able to give the event trigger all the info it needs

glacial panther
#

Well there's a nullref

craggy crow
#

i tested it manually like i said ealier, it works on non instantiate fish

glacial panther
#

Okay so the clicking stuff works fine then?

#

It's just purely the nullref?

craggy crow
#

yeah, its null because it needs the script attach to it so that it can display the stats UI, but since it has none attached, it displays a nullref

glacial panther
#

Yes

craggy crow
#

yeah the clicking works 100% im positive

glacial panther
#

Alrighty

#

Do you know how to use breakpoints?

craggy crow
#

no i dont lol sadly

glacial panther
#

Do you use VS as IDE actually

#

Or a different IDE

craggy crow
#

VS's IDE

#

VS as in visual studio

#

do u know how to add that None(Object) part?

glacial panther
#

I'd breakpoint stuff first so you can see exactly where it goes wrong

#

That might help

#

Breakpoints are very useful

#

You've to press this button btw to attach VS to Unity

glacial panther
craggy crow
#

ohhh nice

glacial panther
#

The first part is mostly important, you don't really need conditional breakpoints and such

#

They can be of use is specific cases though, that's for sure

craggy crow
#

i will read into it

#

but this is the code that Unity has on their eventtrigger: using UnityEngine;
using UnityEngine.EventSystems;

public class EventTriggerDelegateExample : MonoBehaviour
{
void Start()
{
EventTrigger trigger = GetComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerDown;
entry.callback.AddListener((data) => { OnPointerDownDelegate((PointerEventData)data); });
trigger.triggers.Add(entry);
}

public void OnPointerDownDelegate(PointerEventData data)
{
    Debug.Log("OnPointerDownDelegate called.");
}

}

#

for the part that says: entry.callback.AddListener((data) => { OnPointerDownDelegate((PointerEventData)data); }); ....I am not sure what "data" can be use for...I've watched a few YouTube videos and they just sort of ignore it and not use it...can they rename it to something else as well

glacial panther
#

data
Is probably the args it passes

craggy crow
#

thats what I was thinking too, but this part throws me off: OnPointerDownDelegate((PointerEventData)data)

#

that data at the end

glacial panther
#

It's a cast maybe from what I can see

craggy crow
#

ahhh okay, not sure what cast is

#

unless its raycast

glacial panther
#

I don't really use these calls much, I just use buttons with onClick and a lot of Actions

glacial panther
craggy crow
#

ok lol

glacial panther
#

it's like doing

float myFloat = 5.5
int myInt;

myInt = (int)myFloat
#

Casts it to another type

#

Or in this case, struct

#

myInt would get the value of 5 btw

craggy crow
#

ah I see why you would say its a cast, make sense

craggy crow
#

it works using the gameobjects that are in the heiracrchy, but for instantiate objects from my prefabs, it wont allow the GameController to be in there because supposebly it is already in runtime and it cannot put itself on the instantiate object

glacial panther
#

The rest I've no idea

#

You just seemingly have to get the right components I think

#

But it's a bit hard to say what is exactly null and if there are multiple things null etc

#

Hence I suggested the breakpoints, did you manage to get it working?

craggy crow
glacial panther
glacial panther
#

And did you get a pop up in Unity of "Do you want to turn on debug mode?"

craggy crow
#

i think i did

#

we have to click attached every time?

#

i clicked ok and then attached at the bottom, then the debugger shows that it is on

#

then i press play on unity

glacial panther
#

Is your IDE configured?

craggy crow
#

okay I dont think i have VS Code

#

wait is it visual Studeio Code Editor?

#

it shows its installed

glacial panther
#

You're just using VS right?

#

Is VS configured

craggy crow
#

what do you mena by configured

#

if it is just the attached to unity, i did that

#

im using Visual Studio 2019

glacial panther
craggy crow
#

no my monobehavior isnt green

#

installing this now: JetBrains Rider Editor

glacial panther
#

No why

glacial panther
#

Which also means breakpoints do in fact not work

#

Because you didn't configure your IDE

#

Also having a configured IDE is essential

#

So much so, that this is a rule

#

I gotta go home now though, I can continue to help you later, but it'll take like 2 hours before I'm home

#

Just make sure your Visual Studio is configured though

#

You can also use Rider, but I'd recommend VS, it's preference though

craggy crow
#

i been using VS so i am use to it and pref it

#

i read that Rider is paid

#

I am following the list

#

i been wanting this configurations as well, i see youtubers had it and did some searching online but there was just too many information that i got lost

#

but the read me helps, hopefully i can get it working

#

you recommend VS 2019 or go for the latest one 2022?

#

nice Monobehaviour is green now

#

it is working on

#

the breakpoint

#

it is possible to do word by word? I am currently only doing line by line and it runs through the whole line and then it stops and produce the error

glacial panther
#

Oh

#

No

#

It breaks a line

#

You can add multiple breakpoints though

#

And you can over over your variables to see the value

craggy crow
#

gotcha then the error says it is aftermy last code

#

but i been messing with it and i saw that i didnt need to put a gameobject on it

#

it works with a script

#

but

#

the script doesnt allow the function o i might have to add a diff function

#

it allows the script while it is still in prefab

glacial panther
#

Not sure what you did

#

Does the problem still persist?

craggy crow
#

yeah the issue is still there

#

even after i put the script there

#

been troubleshooting it all day, still cannot figure out why

#

but heading to bed now, will ttyl

#

Thanks BTW, just wanted to let you know

craggy crow
#

Hey @glacial panther I found the solution! Thanks again for giving me your time to help me troubleshoot it, and providing me x and y information, im sure it was necessary in order for me to get to z. we can close out this thread

glacial panther
#

Well now you know how to use breakpoints :)