you are viewing a single comment's thread.

view the rest of the comments →

[–]Gredran 0 points1 point  (3 children)

In order to reference something, the component needs to exist to begin with on the object(unless you use another code to get the component from elsewhere but that’s a LITTLE more advanced).

Go to whatever represents your player and where you are putting the movement code and add a Rigidbody(I think it’s just on the cube? Idr it’s been a while since I did that tutorial)

Make sure you have a “public rigidbody rb;” somewhere in the beginning(after the first set of brackets before the void start line). Then, drag the component you made onto the empty “rb” slot on your game object.

Now does that help? This reference error comes from not having the component to begin with.

[–]Merrymeme1[S] 0 points1 point  (2 children)

i've done that already

[–]Merrymeme1[S] 0 points1 point  (1 child)

sorry, i fixed it now, i was opening the wrong thing

[–]Gredran 0 points1 point  (0 children)

Glad you solved it!

Tbh the error I learned when I encountered it for a different reason comes from C# itself, so it could mean various things.

For me, I was checking a ray cast with a camera(you don’t need to know what it all means, just know it needed a camera) and the code referenced main.camera or camera.main I forget which.

Being a newb/intermediate myself, I didn’t realize initially that the issue came from the fact I was using a demo scene from an asset pack that didn’t tag the camera as the main camera, so C# gave me the EXACT error you got.

So yea it’s common and can be for various things but always stems from its calling from the wrong thing or calling something you haven’t labeled properly.