Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ChristmasEve · Oct 11, 2017 at 06:13 PM · rotationquaterniongameobjects

Euler angles in inspector

Is there a way to see (and change) Euler angles for gameobjects in the Unity inspector instead of quaternion notation? I want X Y Z instead of X Y Z W. I would think Unity would give this option. It's too difficult to figure out what the angle is in X Y Z W. And, if I do a conversion using a tool and then try to set XYZW in the inspector, other ones change before I can set all 4. So, the only way I can find to set a gameobject's rotation to an EXACT angle is though code.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by YoucefB · Oct 11, 2017 at 10:47 PM

After some tests here is how i did it: (using propertyDrawer)

QuaternionToEuler.Cs (inside a folder with the name 'Editor')

 using UnityEngine;
 using UnityEditor;

     [CustomPropertyDrawer(typeof(Quaternion))]
     public class QuaternionToEulerPropertyDrawer: PropertyDrawer
     {
         Vector3 euler;
         bool initialized = false;
         public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
         {
             if (!initialized) {
                 euler = property.quaternionValue.eulerAngles; // store the current eulerAngles
                 initialized = true;
             }
     
             label.text += " (Quaternion)"; // can be removed, just to know which are Quaternions
     
             euler = EditorGUI.Vector3Field (position,label,euler); // display the field.
     
             property.quaternionValue =  Quaternion.Euler(euler); // convert the eulerAngles back to Quaternion value.
         }
     }

Note: this script will replace any Quaternion field in any Script and display a vector3 field instead of it.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ChristmasEve · Oct 11, 2017 at 11:16 PM 0
Share

This didn't work. There were no errors in your script but, it didn't change the inspector at all. I still just see X Y Z W for GameObject rotations. Please see screenshot. And, it's definitely in a working Editor c# file. alt text

screen-shot-2017-10-11-at-71503-pm.png (64.1 kB)
avatar image YoucefB ChristmasEve · Oct 11, 2017 at 11:44 PM 0
Share

Ah this wasn't meant to override the Transform's component in the inspector but a Quaternion type variable.

There might be an Other Editor script in your Project that is causing this, do you have any? if yes search for one that has this attribute : [CustomEditor(typeof(Transform))] .

avatar image ChristmasEve YoucefB · Oct 12, 2017 at 12:06 AM 0
Share

Definitely not any script that I added. If there is some rogue script (and I mean ROGUE), it must have ridden along with some asset I imported into my project from the Asset Store very early on. I never thought of that! I'm going to have to check all of my scripts in Editor folders and see.

Show more comments
avatar image
0

Answer by Bunny83 · Oct 11, 2017 at 06:40 PM

I don't quite understand the question. The Transform inspector does show euler angles unless you switched the inspector into debug mode.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ChristmasEve · Oct 11, 2017 at 11:18 PM 0
Share

The inspector already is in normal mode (please see my screenshot to someone else's post below). When I switched to "debug" (to see what happens), I saw even more fields appear.

avatar image
0

Answer by Birdman1011395 · Oct 11, 2017 at 08:05 PM

Why, specifically, do you need a Quaternion if you'd prefer to work with Euler angles? A simpler option would be to expose a Vector3 to the Inspector and convert it into a Quaternion during serialization or via your Start or Awake methods.

I didn't find any built in attributes for this, but you could do this on your own as well. You'll need to add an attribute to your main script folder (something like EulerToQuaternionAttribute) and then create a new property drawer in your editor scripts. The ProperyDrawer page covers how to do this very well. The second example explains how to use custom attributes. I'd recommend taking a shot at this, because understanding editor scripts is a useful skill to have.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ChristmasEve · Oct 11, 2017 at 11:21 PM 0
Share

I'm sorry if I didn't phrase the question right. But I don't want quaternions at all. I wish they never existed. I want euler angles in code and in the inspector. I want to be able to just enter in 90, 0, 0 (for example) in three blanks in the inspector labeled X Y Z. I don't have that though. Everyone seems to be puzzled. Am I missing something really simple?

avatar image Birdman1011395 ChristmasEve · Oct 12, 2017 at 12:28 AM 0
Share

Yes, you are missing something very simple: Unity is built using quaternions, not euler angles. The manual goes over this a little and explains the issues with using euler angles. The Transform inspector displays euler angles for ease of reading but still uses the Quaternion struct.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

102 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i rotate an object 90 or -90 degrees upon collision? 3 Answers

How to set y rotation of an object to be z rotation of another? 1 Answer

How to use Quaternion.Slerp with transform.LookAt? 3 Answers

How can I make my game object move like this? 0 Answers

how to rotate bullet towards enemydirection? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges