#Registering files with Unity's Undo System

1 messages · Page 1 of 1 (latest)

ancient haven
#

Hello, need some help with unitys undo system. I'm currently editting asset files directly, eg: using a filereader and filewriter. I need to register the change with Unitys undo system. Is there any way to register the imported files directly with Unity?
Undo.RegisterImporter and Undo.RegisterCompleteGameobject do not seem to work, im guessing because im editting the files and not Unity Gameobjects. I can save copies / temp files and try to register a custom callback for the undo/redo operations, but it seems like that way would create a lot of unneeded garbage. Would i need to create my own diff state system to handle controlling the differences in files?

solid storm
# ancient haven Hello, need some help with unitys undo system. I'm currently editting asset file...

Well creating, deletion, and modification of files is not really supported in the undo system, and is generally recommended against.

Without knowing more it is hard to make a suggestions. But normally you would register undos with the in-memory object.

If you really want to do it with just modifying the files. What you gotta do is basically have two objects, one, a scriptableObject that you register as a undo operation with a incremented value for each time it is registered. And another object or SessionState keeping track of the total undo/redo increment. The idea is that you match the SessionState increment against the ScriptableObject increment to know if it should apply a change. Iirc the ScriptableObject also needs to keep track of the action (read/write/create/delete) that it should perform.

It has been a number of years since I did it, so my memory is a bit fuzzy. But that is the general idea.

ancient haven
# solid storm Well creating, deletion, and modification of files is not really supported in th...

yeah, im taking fbx import files, reading and modifying them and sending them back to disk. The main thing is that i am able to store what was changed pretty easy (either binary or string blocks). the main reason for doing this is that theres some properties inside fbx files that you cant modify using the inspector itself. are you saying to store a scriptable objects with copies of the files modified, and when the session state reads back down to the undo number, tell the scriptable object to write back the file to disk?

#

or to store what was changed inside a scriptable object as data for each undo, and on undo, take that data and overwrite the changed data with the old one?

upbeat slate
#

which properties? maybe it would have been better to use an asset processor instead of this direct modification

ancient haven
#

Vertices and normals inside of mesh properties*

#

i dont know if OnPostProcessMeshHierachy(GO) would be able to change what direction the normals and vertices face after import while keeping 0 rotation value

#

it would be able to change the scale, and set default rotation to 0 defo (Model properties)

upbeat slate
#

you can edit the mesh data there however you like

ancient haven
#

by mesh data, you mean you get acess to the underlying mesh filter, with edges, vertexes, normals etc? and can change them and write them back

ancient haven
#

oh im dumb

#

3 weeks of work, wasted (somewhat

ancient haven
#

still doesnt seem to be able to solve my problem of being able to "undo" my FBX Postprocessing