- Home /
Upgrading to unity 5... lots of errors... please help.
Sorry that my title does not exactly tell what my problems are but it has to do with the upgrade to Unity 5.
I have hundreds of error messages and the unity API Updating Failed.
I have coded all my scripts in Java.
I got lots of these messages and I dont know how to fix them... like this one:
'UnityEngine.Component.hingeJoint' is obsolete. Property hingeJoint has been deprecated. Use GetComponent() instead. (UnityUpgradeable) 'spring' is not a member of 'UnityEngine.Component'
in my script that would be this line:
function Update()
{
mouseY -= Input.GetAxis("Mouse Y") * mouseSensitivity;
mouseY = Mathf.Clamp(mouseY,-20,180);
hingeJoint.spring.targetPosition = mouseY;
}
the other errors are very similar but instead of ".hingeJoint" there are ".audio" and so on...
can someone please tell me how to rewrite this line so I can eventually fix the other 300 errors....
Answer by Kiwasi · Dec 25, 2014 at 10:40 PM
The shortcut properties have been removed from Unity 5 to allow for WebGL. To fix the errors you need to change every property to the equivalent GetComponent form. This breaking change was a key reason why its called 5.0 and not 4.7.
Here is the fix for the above code. For the rest its a long slog of refactoring to fix each error. The fix is the same in every case of the error.
// JavaScript
GetComponent(HingeJoint).spring.targetPosition = mouseY;
// C#
GetComponent<HingeJoint>().spring.targetPosition = mouseY;
Its also worth noting that we were warned about this in the original release announcement for Unity 5.0. Anybody planning to upgrade should start avoiding the short cut properties now. My understanding is that only .transform and .gameObject will continue to work, everything else is gone.
Edite: Someone want to confirm I got the JavaScript syntax right? Thanks
now it says in the error:
No Appropriate version of 'UnityEngine.Component.GetComponent' for the argument list'(UnityEngine.Component)' was found.
sooo if I understand you correctly... I cant access the components directly so I will need to access them via GetComponent or via variable like in this case...
var thehingejointthingy : HingeJoint; and replace every "hingeJoint" with "thehingejointthingy"...or something like this... am I right? because it would be stupid to get the Components every Update circle...
Sorry, just fixed a typo in my answer. You need to use the capital H in HingeJoint.
You were doing GetComponent every frame in update anyway. This way includes one less method call, so will be slightly more efficient. But you are correct, caching the HingeJoint in a local variable will save on performance.
You were doing GetComponent every frame in update anyway.
O_o omg you are right. I am so stupid...
thank you sooo much. now I am ready for unity 5.... hopefully... now I have to update almost 2 years of java coding learning in unity so I can move on and make my vision come true.
for all people out there if you have the same problems like I had. here is the solution.
ins$$anonymous$$d of hingeJoint.something = somethingelse;
just create a new variable at the top of your script. var hj : HingeJoint;
and then in $$anonymous$$onoDevelope go to Search/Replace and replace the hingeJoint with the new var name hj.
or if you want you can also just replace it with GetComponent(HingeJoint).something = somethingelse; but the otherway is more efficient.
Your answer
![](https://koobas.hobune.stream/wayback/20220613174906im_/https://answers.unity.com/themes/thub/images/avi.jpg)