iTween can't access instantiated child.

Hey!

I’ve got this script that is on an object I’m instantiating. It’s got six children, which I’m fading via iTween, in a certain order, as per the script fragment below. It works just fine on the original object, when I’m not instantiating anything. But when I instantiate the object, the iTween argument for the object to be faded throws a nullreferenceexception error. I know it has to do with the object that it’s attempting to tween because I’ve changed that to something that’s not an instantiation, and it fixes the error. I have no idea why… can you explain it? It’s telling me that the object I’m trying to tween is null, when I have it print that object.

Here’s the iTween call:

iTween.FadeTo(flameArray[activeFlame], {"alpha" : 0, "time" : timeToFadeOut, "easetype" : "easeInOutQuad", "oncomplete" : "flameGenerator", "oncompletetarget" : gameObject});

And here’s how I’m determining the object, in the “Start” function:

function Start ()
{
	flameArray = new Array(transform.Find("z_backgroundFire1").gameObject,
						   transform.Find("z_backgroundFire2").gameObject,
						   transform.Find("z_backgroundFire3").gameObject,
						   transform.Find("z_backgroundFire4").gameObject,
						   transform.Find("z_backgroundFire5").gameObject,
						   transform.Find("z_backgroundFire6").gameObject);
	print(flameArray);
	print(transform.Find("z_backgroundFire1"));
	for(var i=0; i<flameArray.length; i++)
	{
		flameArray*.renderer.material.SetColor ("_Color", clearWhiteColor );*
  • }*
  • flameGenerator();*
    }

I had a similar issue. I could get iTween to work fine for linked objects via Inspector, but never with an Instantiated one.

I was following the docs/tutorials that mention that you should link a Prefab to a script by giving it a type of "Transform" in the script. When I changed it to a GameObject, I was able to use iTween with Instantiated prefabs. No NullReferenceExceptions anymore.