Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Dan 23 · Apr 18, 2011 at 10:06 AM · editorsplineundo

Constant error : SaveSnapshot called without previous call to MakeSnapshot

Hi unity boffins,

I have an editor script that provides both a OnInspectorGUI and OnSceneGUI function that are both trying to support undo via Undo.SetSnapshotTarget. I my case the OnSceneGUI provides Handles.PositionHandle to edit spline control points, while the OnInspectorGUI provides int, float and Vector3 fields to edit various parameters.

My problem is I get a constant error message (as per title) every time I edit one of the PositionHandle gizmos?

It doesn't seem to cause any issues (undo works fine) except cluttering my log console.

If I double click on the error in the log it takes me to the: Vector3 newCp = Handles.PositionHandle( cp, handleRotation ); line of my editor script.

The functions that the error refers (SaveSnapshot and MakeSnapshot) are emanating from Handles.PositionHandle but these seem to be deprecated? or at least they are now internal API and not part of the public API documentation.

Because I have a lot of interdependent code I've quickly made a small example of how I call the undo related functions (this should produce the error). Excuse the code compactness.

There are some questions in the comments of the code too.

Thanks

file: ExampleSpline.cs

using UnityEngine; using UnityEditor; using System.Collections.Generic;

[ AddComponentMenu("Splines/Example Spline") ] [ System.Serializable ] public class ExampleSpline : MonoBehaviour { public List<Vector3> knots = new List<Vector3>(); public int numControlPoints { get { return knots.Count-2; } } public ExampleSpline() { knots.Add( new Vector3(0f,0f,0f) ); knots.Add( new Vector3(1f,0f,0f) ); knots.Add( new Vector3(2f,0f,1f) ); knots.Add( new Vector3(2f,0f,2f) ); knots.Add( new Vector3(2f,0f,4f) ); } public void AddControlPoint() { if ( knots.Count > 1 ) { knots.Add( knots[knots.Count-1] + (knots[knots.Count-1]-knots[knots.Count-2]) ); } else { knots.Add( Vector3.zero ); } } public Vector3 GetControlPoint( int idx ) { return knots[idx+1]; } public void MoveControlPoint( int idx, Vector3 v ) { knots[idx+1] = v; } public void RemoveControlPoint( int idx ) { knots.RemoveAt( idx+1 ); } }

file: Editor/ExampleSplineEditor.cs

using UnityEngine; using UnityEditor; using System.Collections;

[CustomEditor(typeof(ExampleSpline))] public class ExampleSplineEditor : Editor { public ExampleSpline m_target; void OnEnable() { m_target = (ExampleSpline)target; }

 public override void OnInspectorGUI() {
     Undo.SetSnapshotTarget(m_target,"Modify Spline");
     bool splineModified = false;

     for (int i=0; i &lt; m_target.numControlPoints; i++) {
         EditorGUILayout.BeginHorizontal();
         Vector3 CP    = m_target.GetControlPoint( i );
         Vector3 newCP = EditorGUILayout.Vector3Field( "CP: "+(i+1).ToString(), CP );
         if ( CP != newCP ) {
             m_target.MoveControlPoint( i, newCP );
         }
         if ( GUILayout.Button("X") ) {
             m_target.RemoveControlPoint( i );
             splineModified = true;
         }
         EditorGUILayout.EndHorizontal();
     }
     if( GUI.changed || splineModified ){
         EditorUtility.SetDirty(m_target);
         // Register the undos when something changes
         Undo.CreateSnapshot();
         Undo.RegisterSnapshot();
     }
     // Can anyone explain if or why I need to call this here?
     Undo.ClearSnapshotTarget();
 }

 void OnSceneGUI() {
     if ( m_target.numControlPoints &gt; 1 )  {
         // Is it correct to call this here as well as OnInspectorGUI()?
         Undo.SetSnapshotTarget(m_target,"Adjust Spline Handles");

         bool splineModified = false;
         for (int i=0; i &lt; m_target.numControlPoints; ++i) {
             Vector3 cp = m_target.GetControlPoint( i );
             Vector3 newCp = Handles.PositionHandle( cp, Quaternion.identity );
             if ( cp != newCp ) {
                 m_target.MoveControlPoint( i, newCp );
                 splineModified = true;
             } 
         }
         // Is GUI.changed relevant inside OnSceneGUI()?
         if ( GUI.changed || splineModified ) {
             EditorUtility.SetDirty( m_target ); 
             Undo.CreateSnapshot();
             Undo.RegisterSnapshot();            
         }
         // Again, do I acutally need to call this?
         Undo.ClearSnapshotTarget();
     }
 }

}

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

1 Reply

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

Answer by Dan 23 · Apr 19, 2011 at 10:47 AM

The issue ended up being I needed to make sure all Undo.SetSnapshotTarget came after Handles.PositionHandle calls.

i.e:

void OnSceneGUI() { if ( m_target.numControlPoints > 1 ) { // Moved from here Undo.SetSnapshotTarget(m_target,"Adjust Spline Handles");

     bool splineModified = false;
     for (int i=0; i &lt; m_target.numControlPoints; ++i) {
         Vector3 cp = m_target.GetControlPoint( i );
         Vector3 newCp = Handles.PositionHandle( cp, Quaternion.identity );
         if ( cp != newCp ) {
             // Moved to here
             Undo.SetSnapshotTarget(m_target,"Adjust Spline Handles");
             m_target.MoveControlPoint( i, newCp );
             splineModified = true;
         } 
     }
     // Is GUI.changed relevant inside OnSceneGUI()?
     if ( GUI.changed || splineModified ) {
         EditorUtility.SetDirty( m_target ); 

         // Register the undos when something changes
         Undo.CreateSnapshot();
         Undo.RegisterSnapshot();            
     }
     // Again, do I acutally need to call this?
     Undo.ClearSnapshotTarget();
 }

}

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 adurdin · Jan 20, 2013 at 01:42 AM 0
Share

Thank you! I was having the same error, but this seems to have fixed it without impacting the ability to undo. Though I still don't understand how it works when SetSnapshotTarget() is called after the handle has (presumably) started editing the object.

avatar image .sanders · Feb 22, 2013 at 02:40 PM 0
Share

Thanks man for clearing this out for me! Seems like unity could use a proper Undo tutorial in order to get all calls at the right time.

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

2 People are following this question.

avatar image avatar image

Related Questions

unity not undoing transform changes? 1 Answer

How to record hideFlags for Undo/Redo 0 Answers

drawing path on the polygon surface and insert objects along that path 1 Answer

Undo.RecordObject doesn't work 2 Answers

Can my EditorWindow intercept Undo Redo Keyboard commands? 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