- Home /
Issues with 3.3 to 3.4 javascript update
i use getComponent somewhat regularly and once upgraded to 3.4 everything seems to blow up. I did see the JavascriptGuide with the release notes but i'm havin issues figuring it out in this situation:
var UnlockedLevelObject;//set up empty variable for a gameObject
function Start () {
UnlockedLevelObject = GameObject.Find("LevelCarrier");//fill the empty variable with instantiated gameObject
var LevelCarrierObject : LevelCarrier = UnlockedLevelObject.gameObject.GetComponent(LevelCarrier);//access variable in found gameObject above
LevelCarrierObject.LevelToPlay = 0;//set variable insode that gameObject
}
Thoughts?
There's no way to help you if you don't specify the problem you are having. The code you posted above works perfectly fine, compiles and runs without errors and as expected.
@FTheCloud 3.4 is only unstable on windows, which should be fixed with the release of 3.4.1 in the co$$anonymous$$g week. The problem he is having seems to be unrelated to this however, so I don't see why you think it's useful to suggest downgrading.
The script above compiles fine in 3.3, but in 3.4 is throws this(I make calls like this quite a bit so i get $$anonymous$$ANY of the same errors)
Asset/Scripts/test.js(7,69): BCE0019: 'gameObject' is not a member of 'Object'.
i think it has something todo with this:
http://unity3d.com/unity/whats-new/unity-3.4#javascript-upgrade-guide
I've tested this script, even a second time just now just to make sure, and it compiles and works just fine - on 3.4 of course. I've had to create a gameobject and a .js named LevelCarrier of course, with a single variable int named LevelToPlay, to make it all work.
From your error it would seem it's having issues with Unity's API DLL's. Try putting both scripts in a folder in the root of your project named "Standard Assets" to see if this fixes it, since scripts in this folder are compiled earlier and have elevated privileges. If this doesn't fix it, try re-installing Unity.
It's definitely not a problem with your code.
Answer by Eric5h5 · Aug 20, 2011 at 05:25 AM
You shouldn't use untyped variables, such as "var UnlockedLevelObject;". You should supply the type either explicitly or by using a value. (e.g., "var foo = 5;" is fine because it derives the type (int) by the fact that you supplied an int as a value.) In this case, the type should be GameObject.
You should specify whether you're doing iOS/Android programming, because in that case, Unity 3.4 adds an invisible "#pragma strict" to all scripts. This doesn't happen if you're doing web/Mac/PC programming. So "this code doesn't work in Unity 3.4" isn't really true--in some cases it does, in some cases it doesn't. (As an aside, you'll find coding easier if you follow the convention of using lowercase for variable names, leaving uppercase for classes and functions.)
Clever, I forgot about the new invisible #pragma strict and only tested for normal.
@Eric5h5 - Thx man, 3.3 made me lazy, i went in a specified my types and everything is good
@Joshua - Thx for the help mate, and after seeing what 3.4 did to my game's performance...holy &^. Game is running and instantiating on the Android wicked fast, just need to test on a 3.0 device and i'm ready for an update.
Thx again fellas.
Your answer
![](https://koobas.hobune.stream/wayback/20220612184713im_/https://answers.unity.com/themes/thub/images/avi.jpg)