Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to Save / Load Obi Actors in 5.0
#12
(26-10-2020, 10:53 AM)josemendez Wrote: Hi Elegar,

Sorry! I misunderstood what you wanted. Blueprints are just assets, they're already serialized to disk by default. You just need to store particle positions/velocities in the blueprint. For this you can call actor.SaveStateToBlueprint(blueprint), passing the blueprint you want to store the data. Just make sure the blueprint has enough capacity to store all particles, easiest way to do this is instantiating the blueprint used in the first place to create the rope. See this related thread:
http://obi.virtualmethodstudio.com/forum...p?tid=2201

Note that if the rope has changed length or been torn at runtime, these changes cannot be saved in a blueprint.
Hello again Jose
Thanks for such a quick answer! I almost done what I wanted, but still small issue doesn't allow me to be completely happySonrisa
I've read that another thread and it was extremely useful (almost my case). But when I commented out "GenerateImmediate();" from ObiRopeBlueprintBase.cs Unity stopped to save changed blueprints to disk... 

I had a following scenario before removing "GenerateImmediate();": press Run to launch simulation - twist the ropes - press button which calls my Save() function - stop simulation - click "save project" to write changed blueprints to disk. Worked like charm, blueprints files were changed and particle positions were saved inside. But when I launched simulation again or restarted Unity or reopened the scene, ropes returned to their very initial state. At this point I understood why you adviced to remove  "GenerateImmediate();"

Well, I removed it. Everything seems to be fine. I was able to twist the ropes, save them, relaunch simulation. But I noticed that blueprints files are unchanged since that moment. So all these changes lived only in Unity's memory and disappeared when I restarted Unity. But the whole point is to save them permanently... Any advices?

Here is my short script attached to the Rope, may be it can be useful:
Code:
using UnityEngine;
using Obi;

public class RopeSaveLoad : MonoBehaviour
{
    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.I))  Save();
    }

    public void Save()
    {
        GetComponent<ObiRope>().SaveStateToBlueprint(GetComponent<ObiRope>().blueprint);
    }
}
Reply


Messages In This Thread
RE: How to Save / Load Obi Actors in 5.0 - by Elegar - 26-10-2020, 07:57 PM