Alternatives to obsolete methods?

Hello, Uniteers!

Is there a recommendation regarding the 2 compiler warnings below?

warning CS0618: 'UnityEngine.Quaternion.SetEulerAngles(float, float, float)' is obsolete: 'Use Quaternion.Euler instead. This function was deprecated because it uses radians instad of degrees'
warning CS0618: 'UnityEngine.Component.active' is obsolete: '"the active property is deprecated on components. Please use gameObject.active instead. If you meant to enable / disable a single component use enabled instead."'

In C#, there doesn’t seem to be anything called “Euler” as a member of Quaternion. There is a public member called “eulerAngles” but it’s read-only. So how do we get at the recommended “Quaternion.Euler” from C#?

Similarly, there is no property or member called “enabled” exposed from Component (that C# can see). What should we use?

In both cases, we’ve made everything work fine in spite of the warnings, but I never like to live with warnings for any longer than necessary so I would like to find out the right way to do these things.

Thanks very much for any enlightenment!

Quaternion isn’t C#, it’s a Unity thing which applies to all languages. Look up Quaternion.Euler in the docs; it’s there. :slight_smile:

Any components can be enabled or disabled…renderer.enabled = false, collider.enabled = false, etc.

–Eric

Thanks, Eric.

Yes, I’m very familiar with quaternions and euler angles in general. What I was saying is that from the perspective of C# (which is what is exposed from UnityEngine.dll), there is not a member called “Euler” exposed from the Quaternion class. I assume there is such a thing in Javascript as the docs indicate, but not on the Quaternion .net class that is exposed from UnityEngine.dll.

Ditto for “enabled” on components such as Collider and WheelCollider. There is no public member called “enabled”, only “active”, which is marked as obsolete.

I see that these are in the documentation and assume that they are available from Javascript, but they aren’t from C#. Here is everything that Component exposes:

“Enabled” isn’t there.

Maybe I’m referencing a bad version of UnityEngine.dll? Even so, the obsolete warning refers to it… I think this is the latest from the currently public web player, but I will check…

Everything that is in the Unity API is language-agnostic; nothing is limited to one language or another. It would be kind of absurd for a warning to tell you to use something that you can’t. :wink:

Javascript:

var foo = Quaternion.Euler(Vector3.one);

C#:

Quaternion foo = Quaternion.Euler(Vector3.one);

If it’s in the docs, you can use it, so yeah, I expect you do have a bad version of UnityEngine.dll.

–Eric

Not true, unfortunately. For example:

WheelCollider collider = component as WheelCollider;
if (collider != null)
    collider.enabled = false;

gives:

error CS1061: 'UnityEngine.WheelCollider' does not contain a definition for 'enabled' and no extension method 'enabled' accepting a first argument of type 'UnityEngine.WheelCollider' could be found (are you missing a using directive or an assembly reference?)

However, thanks to your help I did find Euler on the Quaternion class; it’s a static method so that does work exactly as you posted. Thanks for that!

This is not the end of the world because .active seems to do the right thing (at least for this release), but it’s uncomfortable having the warning about using an obsolete property (it might go away on the next release?)

Not everything has an enabled member.

If you look at the documentation, there’s no “enabled” definition for Component:

It’s defined individually for Behaviour:

or for Renderer:

It’s not available, however, for Collider or RigidBody:

In case of colliders, the easiest way is to enable isTrigger if you want to disable collisions.

That makes sense. Thank you very much for the reply!