I'm trying to make my own editor so I can rotate object around some point directly on scene view using my own handler.. It's working fine on the scene view but somehow when I try to record it in animation, the rotation change isn't recorded.. when I checked, the value on inspector changes as I rotate using my handler.. I try to rotate it using it's default handler, it's recorded.. but then I used my handler again, the rotation value on animation window doesn't change.. here's my screenshot
I tried several method and then I noticed that OnValidate function is invoked when I change some attribute through inspector but isn't invoked when I used my handler.. So I think It's probably because the changes on my object isn't validated yet.. anyone know how to validate object manually or anyone has any other idea what's actually happening?
Same problem here!
Ironically, this was really annoying in a different tool I did, but now this is exactly the behavior I want, because I'm trying to map hue rotation to a transform.rotation so that I can use quaternion interpolation when there's an Animator Blend.
I've tried SetDirty on everything I touch, to no avail. Hope there's a workaround because this was going to save me lots of work!
I tried this script:
And it isn't recorded either..
I have exactly the same problem, did anybody find a solution?
Answer by Bunny83
Jun 07, 2014 at 07:38 AM
Well, does your editor use SerializedObject and if not do you use EditorUtility.SetDirty on your object after you changed it?
Since the question got bumped again i had another look at the AnimationWindow code. It looks like the AnimationWindow uses the Undo system to record the changes. There is the "Undo.postprocessModifications" delegate to which the AnimationWindow subscribes to receive all changes that go through the Undo system. So make sure you register all your changes to the Undo system.
If you want to recreate the Transform inspector you might want to take a look how the original is implemented. For example if the rotation GUI got changed, the default TransformInspector executes this line:
Which will record the state of the current selected objects. I'm not sure how or where it records the position / scale change since it uses "EditorGUILayout.PropertyField" which is complicated as hell :D. It's also possible that Unity might perform this Undo registration through the SerializedObject when you call ApplyModifiedProperties(); at the end. ApplyModifiedProperties is implemented in native code, so we don't know what happens there.
Though chances are high that you're missing the ApplyModifiedProperties call at the end of your custom editor code which will actually "submit" the changes you made to the SerializedObject to the actual object.
I used EditorUtility.SetDirty(target).. I don't know how to use SerializedObject.. any sample code about transforming after being SerializedObject?
Answer by Alex_May
Feb 29, 2016 at 09:30 PM
I have submitted this as a bug: https://fogbugz.unity3d.com/default.asp?775426_8rnlh0mit52jnbmt
I doubt that this is a bug. It's more likely you're missing something. Did you attach your code to the bugreport? We (the community) can't see if there is a project attached or not but your bugreport would be pointless without.
Properties edited during OnSceneGUI
Properties edited during OnSceneGUI
This is way to vague. There are many ways how to "edit" things the wrong way.
See my edited answer for more details.
Also your post doesn't seem to be an answer, so a comment would be more appropriate.
You might want to have a look at the examples over here. They always use at least either a SerializedObject and ApplyModifiedProperties at the end, or they register the change manually with Undo.RecordObject / Undo.RecordObjects.
Sorry about the answer - I thought this was on the forum for some reason!
I did attach the project to the bug, since this was my first bug report I didn't realise that I should provide instructions to reproduce the bug from scratch.
By "editing properties", I mean that I use a handle to change a vector in OnSceneGUI, this is done simply by e.g. target.offset = Handles.PositionHandle(target.offset). I didn't realise I'd have to add undo / applymodifiedproperties! I didn't even know the latter existed, though I did try SetDirty to no avail. I will have a look at this and get back, since my project is at home and I won't be able to access it until tomorrow.
Thanks for all the info!
OK, I reimplemented my solution locally and fixed the OnSceneGUI function to correctly record Undo if the handles moved the object. The animation now records the offset when it's moved using the handle now! Thanks a lot. If anyone finds this in the future here's the code I used in my OnSceneGUI:
public void OnSceneGUI()
Machine m = (Machine)target;
Vector3 p1 = m.transform.InverseTransformPoint(Handles.PositionHandle(m.transform.TransformPoint(m.expelPositionLocal), Quaternion.identity));
Vector3 p2 = m.transform.InverseTransformPoint(Handles.PositionHandle(m.transform.TransformPoint(m.attachedObjectPosition), Quaternion.identity));
Debug.Log("Moved attach point");
Undo.RecordObject(target, "Move attach point");
m.attachedObjectPosition = p2;
m.expelPositionLocal = p1;
The trick was to stash the changes in a local vector, then if the change check returned true, record into undo, apply the changes, then set the object to be dirty. The target is still a simple MonoBehaviour with some public Vector3 members that are edited by the handles in this function.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
26 People are following this question.
Exact Rotation Around Another Point Over Time
Can I make animations snap to a frame?
Trying to calculate the required relative rotation...
How to rotate a bone during an animation?
Increase NavMesh Rotation Speed