Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by AliAzin · Apr 15, 2010 at 10:08 AM · saveloadfile-io

How to save and load node-based tree network data to a file?

Hi, I'm working on a non-game unity project for managing production pipeline. In there I have a tree network that each node can have one input and a number of outputs. And I need to save the network in a file. How should I do that?

Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by duck · Apr 15, 2010 at 10:26 AM

In Unity you have full access to .net's File IO functions, which you can use to write any kind of data you like (providing you're not targeting the webplayer).

You may need to decide on some text-based format in which to encode your tree node data, and then write a 'reader' and a 'writer' which converts your tree data to and from the text format.

You could also google "c# reading and writing text files" which turns up a load of tutorials, most of which are applicable to Unity.

If you need more help, you might need to supply more detailed information about the kind of data that you want to save.

To traverse a tree system and convert it to a file-savable string, you'd want to use a recursive function call, where each call to convert a node also adds that nodes children to the string - something like this pseudocode, which uses a JSON-like format:

(untested - for illustrative purposes only)

public string Serialize() { StringBuilder s = new StringBuilder(); SerializeNode(rootNode,s); return s.ToString(); }

public void SerializeNode(Node node, StringBuilder s) { s.Append(node.name); s.Append(":["); bool firstChild = true; foreach (Node child in node.children) { if (!firstChild) { s.Append(","); } s.Append(SerializeNode(child,s); firstChild = false; } s.Append("]"); }

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AliAzin · Apr 15, 2010 at 10:34 AM 0
Share

thanks for the reply, but my problem is not handling files. I have problem to walk through nodes in a ordered pattern for saving them.

avatar image duck ♦♦ · Apr 15, 2010 at 01:20 PM 1
Share

you'll have to provide more information about the code that you're using to build the node-based data in the first place then - but essentially you'd probably want a recursive function which passes a stringbuilder reference along so that each recursion adds its own data to the end of the string, which is then written to a file.

avatar image duck ♦♦ · Apr 15, 2010 at 01:54 PM 0
Share

see edited answer.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to script a Save/Load game option 17 Answers

Help with Object position and state, save and load. 1 Answer

how to make a save and load function 0 Answers

Problem Saving game progress 1 Answer

Can't get serialization Load/Save to work!C# 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges