Object Type Mismatch Error Dilema

I’m getting the following error when I run my Unity project:

Here is an edited version of the code that it I believe it is refering to:

What I can’t figure out is what is causing the error.

It looks like Unity is telling me that the object declaration for “instantiatedProjectile” doesn’t match the instance parameters, but it is clearly a Rigidbody type in both. And, I can confirm that I have attached a Rigidbody (prefab) in the parameters panel.

So, what could be causing this error?

TIA, all!

Have you tried it with the variable declaration separate from the assignment to see if it works that way? i.e.

var instantiatedProjectile : Rigidbody;
instantiatedProjectile = Instantiate (projectile, transform.position, transform.rotation);

Are you sure you get the exception from the instantiate call?

lfrog: Thanks for the tip, but it didn’t change anything.

Joe: I put Debug.Log’s in a few places and it sure looks like it’s the instantiation that’s causing the error.

Can you post the full script.

Sure thing.

I’ve resisted the urge to clean it up so you can see the whole magillah. :wink:

var projectile : Rigidbody;  //  "projectilce" is a GameObject
//
var missileLife = 10.0;  //  destoy missile ten seconds after launch
var fireRate = 0.5;  //  wait half a second before alowing next missile launch
var initialSpeed = 20.0;
//
private var launcherOffset = 5;  //  missile up offset form launcher at launch
private var nextFire = 0.0;
//
var ammoCount;
var barGUIWidth;
var ammoStart = 20.0;
//
var barGUI : GUITexture;
var hudXTextureIndex = 0;
var hudXTexture1 : Texture2D;
var hudXTexture2 : Texture2D;




function Start ()
{
	ammoCount = ammoStart;  //  set ammo counter to start amount
	barGUIWidth = barGUI.pixelInset.width;
}



function Update () {
	
	//  fire processing
	
	if (Input.GetButton ("Fire1")  Time.time > nextFire) {

		//  reset fire timer
		nextFire = Time.time + fireRate;
		
		// create a new projectile, use the same position and rotation as the Launcher.
		//  var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
		var instantiatedProjectile : Rigidbody; 
		instantiatedProjectile = Instantiate (projectile, transform.position, transform.rotation); 
		
		// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
		//  instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));

		// Ignore collisions between the missile and the character controller
		Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
			
		//  destroy this missile instance after a set time
        Destroy (instantiatedProjectile, missileLife);
   		
   		//  cycle texture index
   		hudXTextureIndex++;
   		if (hudXTextureIndex == 2) {hudXTextureIndex=0;}
   		//  Debug.Log(hudXTextureIndex);
   		
   		
   		//  update texture
        if (hudXTextureIndex == 1) {
        	barGUI.texture = hudXTexture1;
        	}
        else {
        	barGUI.texture = hudXTexture2;
        }
        
	}  //  end fire processing
	
}  //  end update

The script works fine for me. Try reassigning the projectile again in the inspector.

I already tried that. Repeatedly, in fact.

Tried closing and re-opening the Unity editor too.

All to no avil.

Solved! Although I’m not sure why …

I completely deleted all instances, reinstanced them, re-attached all scripts and now it works.

I guess my copy of Unity is being visited by Aunt Irma. :wink:

Thanks for your help, all!

‘resisted the urge’ :lol:

Try making a really simple scene with only a game object that has the script attached. and a cube with rigidbody that you then set to be the projectile.

Does that work?
With the script you posted, that worked fine for me.