27-10-2020, 12:43 PM
(27-10-2020, 12:04 PM)josemendez Wrote: Have you tried flagging the asset as dirty using EditorUtility.SetDirty(blueprint); before calling SaveAssets? This is automatically called right after GenerateImmediate() (since it regenerates all blueprint data, so it's always known to need saving after this operation) but not called in any other case, such as manual editing of blueprint data or saving to the blueprint at runtime, as we don't know if/when the user has modified the asset.Finally! Yeah, that's exactly what I missed! Thank you hundered times, Jose!
Anytime you modify an asset, you should flag it as dirty (so that the asset database knows something has changed, and needs writing to disk), then call SaveAssets(). This will cause Unity to iterate over all assets that have been flagged dirty, save them to disk, then clear the dirty flag.
See: https://docs.unity3d.com/ScriptReference...Dirty.html
So for those who will look for how to save twisted rope here's working script:
Code:
using UnityEngine;
using Obi;
public class RopeSaveLoad : MonoBehaviour
{
public void Update()
{
if (Input.GetKeyDown(KeyCode.I)) Save();
}
public void Save()
{
ObiRope actor = GetComponent<ObiRope>();
actor.SaveStateToBlueprint(actor.blueprint);
EditorUtility.SetDirty(actor.blueprint);
AssetDatabase.SaveAssets();
}
}