#need help with character controllers and rigidbodies
1 messages · Page 1 of 1 (latest)
show code and point out the line with the NRE
use a bin site for large blocks of code like #854851968446365696 says
pick a site, paste your code, press the save button, share the link
or just tell me which lines are 58 and 65
58 controller.Move(velocity * Time.deltaTime);
65 if (body.isKinematic)
did you correctly assign those values? also CC and RB don't play well together
if I comment out 58 or the whole OnControllerColliderHit method than the NRE is gone, but so is either walking or rigidbody interaction
that doesn't answer my question, did you assign the values of those variables? and if so, where did you assign them?
oh sry I didn't see you question
private CharacterController controller;
private Vector3 velocity;
that's where you declared the variables, where do you assign them?
sry are those the variables you wanted?
well that's one of them. but also still isn't where you assign their value
if so velocity is constantly changed in update, and controller is assigned here
private void Awake()
{
input = new InputMaster();
controller = GetComponent<CharacterController>();
}```
and the object this component is attached to has a CharacterController component on it?
at this point you should just post the entire class using a bin site
ok
also are there any other errors before the one you are currently trying to resolve?
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
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
no
okay, can you screenshot the errors so i can see the full stack trace?
could I just copy paste it?
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
okay and just to confirm, the object you are colliding with has a rigidbody, not the object with the charactercontroller, right?
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
i don't normally use the CC so i didn't know that it doesn't require an RB on the other object for OnControllerColliderHit to be called. Check if the body is null before checking if the body is Kinematic like the docs show https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnControllerColliderHit.html
ok I'll try that