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 beagrie83 · Sep 20, 2013 at 07:25 AM · arrayarraysxmltextasset

XML File, or Array?

Hi, quick question:

I'm making (or attempting to) make a dialogue system using Xml to store the information. I've got my head around how to do it, but I was wondering, do I need to store the Xml info in an array, or can I just access the file each time it's needed without any performance/loading issues.

The files themselves aren't that big, and are brought into the script as a TextAsset.

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
0
Best Answer

Answer by ArkaneX · Sep 20, 2013 at 08:14 AM

Accessing a file is always much slower than accessing data in memory. Especially when you have to search for data.

If the files aren't big and loading them won't introduce memory problems (which might be important on mobiles), then I suggest preloading the data at the beginning of game. Or alternatively, if different files are loaded at different stages of your game, then you can load required files at the beginning of the stage.

I don't know the structure of your files, but if you can simply load their raw data (without xml tags) into arrays - go for it. But if the structure is more complicated (nodes have attributes, child nodes, etc.), then you need to prepare a proper classes in your game and then use them to deserialize your files. If you don't know what deserialization is, please read this Unity Wiki page and maybe this MSDN page.

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 beagrie83 · Sep 20, 2013 at 08:25 AM 0
Share

Thanks for the reply, ArkaneX.

I am (as you've probably guessed) quite new to this. I was under the impression that loading the Xml file into a TextAsset and accessing that was effectively loading it into memory (I realise now the title of the question is misleading), is this not so?

As for the structure, it will be fairly complex. The files don't just contain the dialogue, but also flags for when the dialogue can be applied, and information on what the player can respond with and where to go next, etc.

I'm using Xml because the other person working on the game can get their head around Xml easier, so they can edit the files.

avatar image ArkaneX · Sep 20, 2013 at 09:11 AM 0
Share

You're right - if you load it once and then only access it as 'in memory representation', then it will definitely be faster than accessing actual file on disk.

Anyway - after you have TextAsset instance, you still has the whole X$$anonymous$$L string in memory, and searching it might not be a best option. It is possible to load it into XmlDocument class, and then search using xpath, but preparing dedicated classes and using deserialization is still better approach.

avatar image beagrie83 · Sep 20, 2013 at 09:36 AM 0
Share

Thanks. I do currently have it as a TextAsset that is then loaded into an XmlDocument class, but I will bone up on dedicated classes as an alternative.

Thanks again.

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

16 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

Related Questions

Save and load arrays into an XML file 1 Answer

Problems with Arrays 2 Answers

IndexOutofRangeException 1 Answer

my QandA array is not working when you choose 3 wrong answers 1 Answer

Array empties values on RunTime? 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