Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to Save / Load Obi Actors in 5.0
#17
(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.
Reply


Messages In This Thread
RE: How to Save / Load Obi Actors in 5.0 - by josemendez - 27-10-2020, 12:53 PM