Error CS0619: Unity.Component.camera is obsolete

Hi,

I received the following error message in MonoDevelop-Unity when completing the assignment for Lecture 30:

Error CS0619: UnityEngine.Component.camera' is obsolete:Property camera has been deprecated. Use GetComponent() instead. (UnityUpgradable)’ (CS0619) (Assembly-CSharp)

I am confused on how to fix this error. What should I change in the code? This is what I currently have:

Camera camera = GetComponentInChildren<Camera> (); camera.transform.localRotation = Quaternion.Euler(-mouseY, 0, 0) * camera.transform.localRotation;

Thank you.

Now that I have restarted MonoDevelop-Unity the error message is gone. Instead I get the following message:

“Solution loaded.”

I think this is because I said “yes” when Unity asked to add older scripts via the API Updater.

I am happy that there no longer seems to be an error. However, I would really love to understand how I could have solved the error by changing my code instead of using the updater. Thank you.

1 Like

Hi @sampattuzzi could you please teach me how I could have gone about correcting the deprecated Property Camera in my code by using GetComponent( ) instead as advised by my Error message?

Thank you! :slight_smile:

I’m not sure I understand. What’s wrong with your approach?

Hi @sampattuzzi , thank you for your reply.

Well as far as I can understand, MonoDevelop-Unity seems to advise me to use GetComponent( ) instead of Component.camera.

I didn’t make any changes in the code, I just did an updated the API. I know this works fine, I am just curious if there was another way code-wise to fix the issue without doing an API update.

Could I have tweaked something in the code? If so, what?

Thanks again Sam! :slight_smile:

I don’t see Component.camera in your code.

Hi @sampattuzzi , that was exactly my question. MonoDevelop tells me that my Component.camera is obsolete and that the Property camera has been deprecated. It tells me instead to use GetComponent( ). However, I do not see that I am using Component.camera in my code. Confusion…

Have you tried restarting Unity and MonoDevelop? I would expect the issue just to be that the error message hasn’t caught up unless there is a reference to Component.camera that you are missing.

Hi @sampattuzzi, thanks for your reply. Okay, I will just consider it to be something a little strange with MonoDevelop. The issue was resolved anyway with the updater, so all is well. Thanks again!

@Blue, are you using the same version of Unity as Sam in the lectures? I think the version in the lectures is a bit older than the currently-available version. 5.3 vs. 5.4 ?? I am using the latest (v5.4.0.3f on Mac) and received the same Camera deprecation errors as well as a dialog popping-up when using the camera. I answered “No” to that dialog and was able to get around it somehow.

2 Likes

@Dondi_Fusco, you are right, I am using the same version on the same OS as you are. I got the same dialogue. I think (if I remember correctly), I said “yes”? Anyway, whatever happened the issue disappeared. I am glad your error went away too! Weird stuff :robot:

Privacy & Terms