u3b6 - has GetComponent changed?

Hi dudes,

I’m a bit confused. Until I upgraded from beta5 to beta6, this worked fine:

private var tiltToTurn : TiltToTurn;

function Awake() {
	tiltToTurn   = gameObject.GetComponent (TiltToTurn);
}

(TiltToTurn is the name of one of my scripts).

Now I get a complier error:

Assets/Player/Jump2.js(55,48): BCE0022: Cannot convert ‘UnityEngine.Component’ to ‘TiltToTurn’.

Has the compiler’s behaviour become more strict? If so, can anyone tell what subtlety I have failed to grasp?

There are a few other examples of casting not working right after my upgrade. Here’s another:

var playerModel : GameObject;
var plumeMaterial : Material;
var plumePrefab : Transform;
var switchedOn = false;
var myRigidbody : Rigidbody;
var emitterForce: Vector3;
var plume : GameObject;

function Awake() {
	myRigidbody = rigidbody;
	
}

function OnCollisionEnter(collision : Collision) {
	
	if (collision.gameObject.layer == 9) {
		if (switchedOn) {
			var contact = collision.contacts[0];
			var rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
		        var pos = contact.point;
			plume  = Instantiate(plumePrefab, pos,rot);
		}
	}
}

…the line plume = Instantiate(plumePrefab, pos,rot);

throws this:

Assets/Player/CrashEmitter.js(23,45): BCE0022: Cannot convert ‘UnityEngine.Object’ to ‘UnityEngine.GameObject’.

the changelog mention the informations on the UnityScript changes with Beta 6 where UnityScript went to an all new level

Howdy,

on your GetComponent() line add " as TiltToTurn" to the end.

for whatever reason, i had thought “as TYPE” was a C# only thing. but it now seems to get past casting errors in the b6 version of JS.

I had a bunch of problems when I tried to open a current Unity iPhone 1.7 project in Unity 3 a little while back.

Are these problems in conversion going to remain in the final release of Unity 3 (i.e. a lot of recoding to correct syntax problems when opening older projects) or is the issue simply that the project conversion isn’t fully fleshed out yet in the betas?

on the iphone its a known behavior, not a problem actually (no dynamic typing there at all)

On U3 it might not be a problem either but a consequence of the presence of generics on UnityScript since Beta 6 (as mentioned, see changelog)

And there is now officially no JS anymore, its called UnityScript from what I’ve seen (finally, cause JS caused a lot of missunderstanding and with generics now its not even in the same league anymore)

One example wasn’t even around declaration, but simply raycasting. I have a forum topic about that here:

http://forum.unity3d.com/viewtopic.php?t=59231

I’ve kinda just let it go for now assuming that it was just a bug in the beta.

This is why I love unity - I wake up after an evening of headscratching, and I have both short-term and long-term advice!

Montgomery, your advice fixed my issue, thank you!

Cheers Dreamora, I’m now off to read obout generic types…