I’m getting an error with the following function:
The error is: “The out parameter ‘input’ must be assigned to before control leaves the current method”
public void FindGrabAxisOnPart(out ObjectPart input)
{
Vector3 grabAxis = Vector3.zero;
int grabAxisInt = -1;
int upAxisInt = -1;
if (input.collider)//if it has a collider
{
grabAxisInt = ObjectPart.X_AXIS;
upAxisInt = ObjectPart.Y_AXIS;
//int biggestAxis
Vector3 size = input.collider.bounds.size;
List<float> axes = new List<float>() { size.x, size.y, size.z };
axes.Sort();
input.grabAxis = GetAxisVector(axes[axes.Count-1], size);
input.upAxis = GetAxisVector(axes[axes.Count-2], size);
input.grabRadius = GetGrabRadius(axes);
input.ZeroRotation = Quaternion.LookRotation(input.grabAxis, input.upAxis) * Quaternion.Euler(input.grabAxis * 90f);
}
}
I don’t get it. It’s assigned to before i even CALL the function, because i pass in a non nulled variable. This function just modifies some properties of it (It’s a custom class, ObjectPart)
For what it’s worth, here’s the sourcecode of ObjectPart too:
public class ObjectPart
{
public Rigidbody body;
public Collider collider;
public float massProportion;//How much of the object’s total mass, that this part weighs
public float smallestSize;
public float grabRadius; //The length of the grab axis, in either direction, starting from the middle
public Vector3 grabAxis;
public Vector3 upAxis;
public Quaternion ZeroRotation;//The rotation which causes this object's GrabAxis to align with World Z Axis, and the upAxis to Align with World Y Axis
public const int X_AXIS = 0;
public const int Y_AXIS = 1;
public const int Z_AXIS = 2;
public ObjectPart(Rigidbody input)
{
body = input;
}
public string ToString()
{
return "b" + body + " c" + collider + " m" + massProportion + " s" + smallestSize;
}
}