null reference exeption? (Solved)

I’m given a null reference exeption error here
rayDistance = controller.height * .5 + controller.radius; which results in this error

at this line here

if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance))

Which makes no sense to me i mean there is no reson in my eyes why this would be zero as if it isn’t picking up the character controller or the params inside it.

the effected code is this can anybody see where the problem might be?

private var rayDistance : float;
private var controller : CharacterController;
private var myTransform : Transform;
private var hit : RaycastHit;

function Start ()
{
	myTransform = transform;
	rayDistance = controller.height  * .5 + controller.radius;
	controller = GetComponent(CharacterController);
	
}

        if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance)) 
{

{

You’re referencing “controller” before you’ve defined it.

–Eric

Is that Raycast simply outside of a function body?

Are you certain that Raycast is being called after Start?

Double check what controller height and radius is at the time of the call.

@Eric: thank you. I forgot about ordering in the start function lol.

@Ntero: no that is usually inside a fixed update i just forgot to add that in the code example.