27-10-2020, 12:53 PM
(This post was last modified: 27-10-2020, 12:55 PM by josemendez.)
(27-10-2020, 12:43 PM)Elegar Wrote: Finally! Yeah, that's exactly what I missed! Thank you hundered times, Jose!
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();
}
}
You're welcome! One final note though (you might know this already, but doesn't hurt to complete the info for future readers): I understand this script is editor-only, as you want to ship the game with all blueprints pre-made. If this script is not in a /Editor folder (like it should if it's an editor script), it will be included in any builds you make, and will result in compilation errors if using stuff from the UnityEditor namespace (as it's unavailable outside the editor). In that case you want to exclude any editor-only code by wrapping it in #if UNITY_EDITOR/#endif preprocessor directives. Like so:
Code:
ObiRope actor = GetComponent<ObiRope>();
actor.SaveStateToBlueprint(actor.blueprint);
#if UNITY_EDITOR
EditorUtility.SetDirty(actor.blueprint);
AssetDatabase.SaveAssets();
#endif
This will exclude the two editor-only lines in case you're building the script to be shipped with the standalone build, and the blueprint will only be saved to memory.