Author Topic: Trying to save and load DataNodes to Assets/Resources/  (Read 2434 times)

col000r

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 43
  • Mighty Emperor of Planet "Home Office"
    • View Profile
    • BLACKISH
Trying to save and load DataNodes to Assets/Resources/
« on: August 02, 2016, 09:45:07 AM »
Hey, I'm trying to save some information from an Editor-script to a Resources folder and then load it back in at runtime, but I'm getting the following error:

  1. Unknown prefix: 85 at position 1
  2. UnityEngine.Debug:LogError(Object)
  3. TNet.Tools:LogError(String, String, Boolean) (at Assets/TNet/Common/TNTools.cs:1001)
  4. TNet.Serialization:ReadObject(BinaryReader, Object, Int32, Type, Boolean) (at Assets/TNet/Common/TNSerializer.cs:2724)
  5. TNet.Serialization:ReadObject(BinaryReader) (at Assets/TNet/Common/TNSerializer.cs:2360)
  6. TNet.Serialization:ReadObject(BinaryReader) (at Assets/TNet/Common/TNSerializer.cs:2351)
  7. TNet.DataNode:Read(Byte[], SaveType) (at Assets/TNet/Common/DataNode.cs:585)
  8. TNet.DataNode:Read(Byte[]) (at Assets/TNet/Common/DataNode.cs:540)
  9. TNet.DataNode:Read(String, Boolean) (at Assets/TNet/Common/DataNode.cs:509)

What I'm doing to save it in the Editorscript is this:
  1. vNode.Write( Application.dataPath + "/_INFO/Resources/" + UnityEngine.SceneManagement.SceneManager.GetActiveScene().name + ".txt", TNet.DataNode.SaveType.Text );

and then I try to load it at runtime like this:
  1. if( !System.IO.File.Exists( Application.dataPath + "/_INFO/Resources/" + v.vesselUID + ".txt" ) ) return false;
  2. vesselNode = DataNode.Read( Application.dataPath + "/_INFO/Resources/" + v.vesselUID + ".txt" );

Why isn't this working? What am I doing wrong? The content of the DataNode is just some ints, Vector3s and strings, nothing special
Games: BLACKISH | Blog | Assets

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Trying to save and load DataNodes to Assets/Resources/
« Reply #1 on: August 02, 2016, 10:04:18 AM »
What's the name of the first node? Seems like it can't determine the type of the file and is defaulting it to binary, when you saved it as text. Either specify the type explicitly in the reading function, or ensure that the first node is named with alphanumeric characters so that it knows that the data is going to be text. DataNode's default is "Version".

col000r

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 43
  • Mighty Emperor of Planet "Home Office"
    • View Profile
    • BLACKISH
Re: Trying to save and load DataNodes to Assets/Resources/
« Reply #2 on: August 03, 2016, 09:35:59 AM »
Thanks for the tip! Now I'm doing it like this an it works:

  1. if( !System.IO.File.Exists( Application.dataPath + "/_INFO/Resources/" + v.vesselUID + ".txt" ) ) return false;
  2. byte[] fileContent = System.IO.File.ReadAllBytes( Application.dataPath + "/_INFO/Resources/" + v.vesselUID + ".txt" );
  3. vesselNode = DataNode.Read( fileContent, DataNode.SaveType.Text );
Games: BLACKISH | Blog | Assets