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
0
Question by GrayLightGames · Oct 06, 2019 at 08:15 PM · resourcesfilesbuildslevel loadcustom class

Store and access a level file with my project

Hi Unity Community,

I have created hundreds of levels in my own level editor and I have them stored in a list inside a custom class. I then serialize this class out to a binary file which I load in my main project and retrieve the list of levels.

Now I'm ready to start deploying, but when I build and test on iOS, I am having difficulty accessing the level file. I thought I might be able to store it in Resources, but since the custom class I made is serializable, I can't make it a subclass of UnityEngine.Object or MonoBehaviour. As far as I've been able to find out, this means I can't use Resources.Load to pull it back out of Resources.

Is there a way I can store a non-UnityEngine.Object class file in my build? Feels like there must be... I'm thinking I can redesign my level structure to somehow live inside an object in my scene, or maybe have the program download the level file from a server, but it would be cleaner if I could just have it be part of the main deployment.

Thanks much in advance for any help/advice!

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 GrayLightGames · Oct 06, 2019 at 09:44 PM

Well, found some info in another post and came up with a solution. I'm storing my file in Resources with the .bytes extension. When loading, my game checks Application.PersistentDataPath to see if the file is there. If it is not, it loads the file from Resources as a TextAsset (if you can believe that). Then I write a file to PersistentDataPath from the TextAsset.bytes and voila. Still seems a bit much to go through, but I'm storing a <1MB in Resources that should only be loaded one time. Here's a little code:

     public void CreateLevelFile()
         {
             Debug.Log("CREATING FILE");
             FileStream file = File.Create(fileName);
             file.Close();
     
             Debug.Log("LOADING TEXTASSET");
             TextAsset tempAsset = Resources.Load<TextAsset>("LevelData");
     
             Debug.Log("WRITING FILE " + fileName);
             File.WriteAllBytes(fileName, tempAsset.bytes);
     
             Debug.Log("CLOSING FILE");
             file.Close();
     
             Resources.UnloadAsset(tempAsset);
         }

If anyone has a nicer way to do this, would be great to hear. For now I'll run with this. Here's the other post I found for some more elaboration: Read Binary Files From Resources

Comment
Add comment · 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

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

113 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does my Unity project contain tens of thousands of files when the actual game assets is far less? 2 Answers

Difference between Resources folder Vs normal folder 0 Answers

Unity 5.6 build size increases? 4 Answers

Load xml from resource folder after build(web player) 0 Answers

[Android] Resources folder: number of files limit? 0 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