I am making a player controller using a main character controler, with the graphics and colliders sitting as components of children of this object. I am running into a problem where Unity for some reason thinks the Character Controller counts as a “component in children”, and it uses it instead of the actual collider I want to my character.
Not only that, but the Character Controller itself is being calculated as a collider and I don’t want that. I want it to be completely incollidable with everything, and use different colliders to track collisions.
GetComponentInChildren first searches the object you called it on, then searches all of its children. If you want a specific Collider in your character’s hierarchy, the simplest way to do that is to set up a [SerializeField] or public Collider field on your player script and drag and drop the one you want into the slot it creates in the inspector.
If that’s what you want, there is no reason to use CharacterController at all. Just move your character by setting transform.position. The point of the CC is to move and do collision detection for you.
I think there’s a fundamental misunderstanding about what the CharacterController component is. The CharacterController is an always upright CapsuleCollider when viewed from the physics system. The CharacterController class is literally derived from Collider. Also a CharacterController does not use the physics system to detect collisions. It uses a raycast based collision detection.
A CharacterController can not “use” any other colliders you may attach to the character controller. Normal colliders do only work with rigidbodies. So the whole setup seems to be flawed if I understood that correctly.
Note that you never want to move a normal collider that is not part of a rigidbody. Again, the charactercontroller is not a rigidbody. From the physics system’s point of view a CharacterController is a stationary capsule. So other rigidbodies can collide with it (according to the collision matrix). Though as I said the CharacterController itself is not a rigidbody and can only use its own upright capsule for collisions.
That wouldn’t work because the code happens while the game is running, I need a way to make so it automatically attaches the player’s body (collider) into the variable.
Without a character controller, I don’t have step offsets, slope limits, the movement is significantly worse… I need the character controller for these things, I just want to get rid of the collider.
The colliders sit inside children, I made them so i can more easily tweak what parts of the player collide, it’s a shooting game so I need colliders for head, torso, legs, etc… I could use rigidbodies, but then I would have to redo all my scripting that uses the features of the character controller.
You still should not attach colliders to a CharacterController without a rigidbody. This will lead into horrible performance becaose a collider that does not belong to a rigidbody is considered a stationary static collider which are not supposed to move at all. If you want to move colliders by scripting you have to use a kinematic rigidbody. Though keep in mind that the CharacterController can not use any of those child colliders for its own movement collisions. Of course you can use those colliders as hit targets for your shooting, however they can not be used for movement collisions when you use a CharacterController.