- Home /
Procedual Collider is not working correctly - Until reset in editor C#
I'm in the process of creating a Procedural game and I'm having an issue with my characters collider. I'm using this code to generate the collider:
GameObject i = Instantiate (playerObj,playerSpawn,Quaternion.identity) as GameObject;
i.name = "Player";
i.tag = "Player";
i.AddComponent<CapsuleCollider>();
i.AddComponent<Rigidbody>();
i.AddComponent<PlayerController>();
i.GetComponent<CapsuleCollider>().center = new Vector3(0,0.5f,0);
i.GetComponent<CapsuleCollider>().radius = 0.25f;
The code is only run once. This should in my mind give something like this
But instead I get this:
The character can still move in the same manner (including jumping) and doesn't seem to be stuck into the ground. The values of the Collider are correct in the inspector however if I edit the value during runtime via the inspector the Collider fixes itself, even with the same values entered. Does anyone know why this is and how I might fix it?
When is this function called? During Edit $$anonymous$$ode? If yes, then you have to use SetDirty after calling it to ensure that the values are kept on runtime.
It runs in sequence with a bunch of other functions on Start. I tried SetDirty but it doesn't seem to make a difference.
Your answer
![](https://koobas.hobune.stream/wayback/20220613185213im_/https://answers.unity.com/themes/thub/images/avi.jpg)