#need help with character controllers and rigidbodies

1 messages · Page 1 of 1 (latest)

foggy abyss
#

so I'm trying to make my player move with a character controller, but still interact with rigidbodies, it's all working how I want it, but I'm getting a NullReferenceException error and can't figure out why

chilly abyss
#

show code and point out the line with the NRE

foggy abyss
#

oh sry

#

I'm not really sure how to do that

chilly abyss
#

pick a site, paste your code, press the save button, share the link

#

or just tell me which lines are 58 and 65

foggy abyss
#

58 controller.Move(velocity * Time.deltaTime);

65 if (body.isKinematic)

chilly abyss
#

did you correctly assign those values? also CC and RB don't play well together

foggy abyss
#

if I comment out 58 or the whole OnControllerColliderHit method than the NRE is gone, but so is either walking or rigidbody interaction

chilly abyss
#

that doesn't answer my question, did you assign the values of those variables? and if so, where did you assign them?

foggy abyss
#

oh sry I didn't see you question

#
    private CharacterController controller;
    private Vector3 velocity;
chilly abyss
#

that's where you declared the variables, where do you assign them?

foggy abyss
#

sry are those the variables you wanted?

chilly abyss
#

well that's one of them. but also still isn't where you assign their value

foggy abyss
#

if so velocity is constantly changed in update, and controller is assigned here

    private void Awake()
    {
        input = new InputMaster();
        controller = GetComponent<CharacterController>();
    }```
chilly abyss
#

and the object this component is attached to has a CharacterController component on it?

foggy abyss
#

yes

#

I also have require component for character controller at the top

chilly abyss
#

at this point you should just post the entire class using a bin site

foggy abyss
#

ok

chilly abyss
#

also are there any other errors before the one you are currently trying to resolve?

foggy abyss
#

I don't think so

#

and so far I haven't noticed any problems coming from the NRE but I'm guessing that I should still deal with it

chilly abyss
#

i need a definitive yes or no. scroll to the top of your console and check if there are any errors coming before these two NRE, any previous errors could be causing these errors

foggy abyss
#

no

chilly abyss
#

okay, can you screenshot the errors so i can see the full stack trace?

foggy abyss
#

could I just copy paste it?

chilly abyss
#

a screenshot of the errors is fine as long as the entire stack trace is included. you can copy/paste it but it will be harder to read due to discord's formatting

foggy abyss
#

I just added the error to the bottom

chilly abyss
#

okay and just to confirm, the object you are colliding with has a rigidbody, not the object with the charactercontroller, right?

foggy abyss
#

the one object does, but I don't know if it's messed up because the floor doesn't

#

the object with the charactercontroller doesn't have a rigidbody

#

ok I decided to test putting a kinematic rigidbody on the floor and it did have an NRE until I touched a different object that didn't have a Rigidbody

chilly abyss
foggy abyss
#

ok I'll try that