Skip to content

Instantly share code, notes, and snippets.

@DomDomHaas DomDomHaas/SaveHook
Created Dec 7, 2014

Embed
What would you like to do?
Unity SaveHook to save all persistencyIds
using UnityEngine;
using UnityEditor;
using JSONPersistency;
using UnityEditor.Callbacks;
public class SaveSceneHook : AssetModificationProcessor
{
static string[] OnWillSaveAssets (string[] paths)
{
Object[] objs = Component.FindObjectsOfType (typeof(JSONPersistent));
//Debug.Log ("OnWillSaveAssets " + objs.Length);
foreach (Object obj in objs) {
JSONPersistent persist = (JSONPersistent)obj;
if (!persist.persistentIDisSet ()) {
persist.loadPersistentID ();
//Debug.Log (persist.name + " loaded! persistID: " + persist.getPersistentID ());
} else {
//Debug.Log (persist.name + " persistID: " + persist.getPersistentID ());
}
}
return paths;
}
}
@xoyojank

This comment has been minimized.

Copy link

commented Jun 15, 2016

this is not work with prefabs in Unity5, because the value LocalIdentfierInFile is 0.

@DomDomHaas

This comment has been minimized.

Copy link
Owner Author

commented Jan 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.