Oscillating values

I have my work cut out for me trying to explain what the problem is… I think I’d best do it with example scripting.

The thing is, I have a Color that I send inside an Array (among other misc values) to a Function, but every update, it resets this Color to Color.black for no reason, while also sending it no problem.

Example:

var color : Color;
function Update () {

if (somethingIsTrue)
{
var arr = new Array();
arr.Push(something);
arr.Push(color);
Receive (arr);
}

}
function Receive (array : Array) {

print (array[1]);
//Print each (or each other?) update is Color, then a color with all 0s, i.e. Color.black with no alpha. If this value is a Vector3, it prints the Vector, then Vector3.zero. If this is a component from another script, it prints the component, then a NullReferenceException. Any ideas? It’s like the script resets itself once every frame, and momentarily reverts all values and component references.
}

It looks like you might actually be resetting it each frame, depending on what the value of somethingIsTrue is. Do you ever change the value of that variable?

You mean it’s the color:Color that is reset to black?

The “somethingIsTrue” is a Raycast. But the color sent in the Array is defined in editor and never changed in the script.

@Brain: The color, or just about anything else that I try to send. I tried constructing a Color from a Vector (x for r, y for g etc), but the Vector also got reset.

Here is the actual Update function. Don’t laugh.

function Update () {


print (container.privateColors[0]); // First prints the color and then a NullReferenceException every frame

if (Input.GetMouseButton(0))
{
 var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    var hit : RaycastHit;
 
    if (Physics.Raycast (ray, hit))
       {
   	
         var meshes : SkinnedMeshRenderer[] = FindObjectsOfType(SkinnedMeshRenderer) as SkinnedMeshRenderer[]; 
		 var closest : Mesh; 
		 var closestTransform : SkinnedMeshRenderer;
    var distance = Mathf.Infinity; 
    var position = hit.point; 
    for (var go : SkinnedMeshRenderer in meshes)  { 
        var diff = (go.bounds.center - position);
        var curDistance = diff.sqrMagnitude; 
        if (curDistance < distance) { 
            closest = go.sharedMesh; 
            closestTransform = go;
            distance = curDistance; 
        } 
    }  	
    
       	var info = new Array();
       	info.Push(hit.point);
        info.Push(ray.direction);
       	info.Push(container.privateColors[0]); //Contains the color, since storing it in this script didn't work.
		info.Push (closest);
		info.Push (closest.vertices);
		info.Push (closestTransform);
		
       	 DeformColor(info); // The function to send to.
       	 
       	 }       
 
}

}

I suspect any objects you pass into DeformColor may be altered?

Do you have the code for that one?

That is true. It creates a new Mesh based on the old one and assigns it to the specified SkinnedMeshRenderer. It doesn’t, however, do anything to the gameObject that with this behavior. You suspect this is the problem anyway?