Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Trouch · Jul 02, 2014 at 05:44 AM · savexmlsavingdialogue

XML File - Step 1?

Hey guys, this is my last hurdle to begin creating my game. I use Json saving and Java, so my XML knowledge is non-existant and all the tutorials seem to assume too much and begin with "just import this code > code"

Im using a plug-in tool, "Dialoguer" and i simply need an XML file to save a string variable, the command to save and everything is already present with the tool, its simply getting an XML file and interacting with it in unity which i dont know about.

So, What are the first steps to get an XML file into unity? (Does unity have the option or do i need visual studio?)

Thanks plenty

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 HarshadK · Jul 02, 2014 at 07:07 AM

You need to write code to read and write files in Unity.

This article about Saving Data#2 which uses XmlSerializer might be helpful for you.

You store your XML file from where you want to access it (preferably Assets folder) and then you access that XML file as you would access any other file from code.

The part from that tutorial where it loads and reads the XML file is as below:

To read from a file we just need to create an instance of XmlSerializer specialised to the root of our XML structure.

  var xmlSerializer = new XmlSerializer();

Now we need to provide that serializer with the data from a stream - if you have a file you just open it:

  var stream = File.Open("somefile.xml");

If we have a string then we might use this:

var stream = new MemoryStream (Encoding.UTF8.GetBytes (xml)); Then to create our entire structure we just do:

  var library = xmlSerializer.Deserialize(stream);

And that's it - we've got the whole thing loaded. You should remember to close any File you've opened of course.

There is also an article on Unity Wiki about Saving and Loading Data: XmlSerializer

Before you jump right into something, I would suggest you to read those articles carefully. :-)

Comment
Add comment · Show 2 · 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 Trouch · Jul 02, 2014 at 07:20 AM 0
Share

Thanks, although to obtain the initial X$$anonymous$$L file, how do i do that? Do i convert an empty C# or Java script file into being an X$$anonymous$$L file or do i need to create an X$$anonymous$$L file and import it into unity?

avatar image HarshadK · Jul 02, 2014 at 07:41 AM 1
Share

You create an X$$anonymous$$L file (create a file with extension .xml) and then import it into Unity.

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving problem unity project 5 Answers

Saving gameobjects' properties for Dynamically growing prefabs 1 Answer

XmlException when trying to read/write XML from iOS device 1 Answer

Save works for computer but not once i create the build and load it on the android 1 Answer

XML and dialogues. 1 Answer


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