Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 msnz · May 17, 2021 at 01:06 PM · assets

Load the contents of an Addressable folder without using labels?

Basically, my game is composed of 1000+ levels, and the content of each level is inside a folder. Each folder contains 3 text files (1.bytes, 2.bytes, data.json) that are used by the level. The goal is to load those text files when they are needed (when a level begins), and then destroy (release) them when they are no longer needed.

This is how I am using Addressables at the moment:

1.) Drag all the level folders inside an Addressable Group titled "Content" and add a label to each folder so it can be loaded later.

alt text

2.) Load the text files from a folder via the code below:

 private AsyncOperationHandle<IList<TextAsset>> aoh;
 
 // this method is called to load the level assets based on level number
 public void LoadLevelAssets(int levelNum)
 {
     string label = levelNum.ToString();
     
     this.aoh = Addressables.LoadAssetsAsync<TextAsset>(label, result => { print(result); });
     this.aoh.Completed += this.OnLevelAssetsLoaded;
 }
 
 // oncomplete handler
 private void OnLevelAssetsLoaded(AsyncOperationHandle<IList<TextAsset>> obj)
 {
     var theList = obj.Result;
     foreach(var item in theList)
     {
         print(item.name); // outputs the files names ("1", "2", "data")
         print(item.text); // outputs the actual text inside the file
     }
 }
 
 // method to destroy/release assets
 public void ClearLevelAssets()
 {
     Addressables.Release(this.aoh);
 }


The issue:
Labeling each folder is fine for testing, but if my game has 1000+ levels, it would be impractical to add a label to each folder one by one. Is using labels really the only way to load a folder? Is there a better way of doing things?

I know another way would be to just mark all the text files as addressable, and load each one via its address, but there doesn't seem to be an easy way to do this too as I'd have to expand each folder one by one and select the text files inside those.

Any insight on a better way to do this would be appreciated. Thanks.

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

Answer by AkamaruDesign · Apr 14 at 11:02 PM

@msnz im trying to do the same thing, here is my posible approach

load everything by its address but, for simplicity need to have a clear way to name each asset, for example

Level 1

 t1.bytes
 t2.bytes
 tData.json

Level 2

 t1.bytes
 t2.bytes
 tData.json

now, for loading each level, you need a generic class that choose what to download at run time.

     private AsyncOperationHandle<TextAsset> part1, part2, partData;
     private List<TextAsset> texts;
     public void LoadLevelAssets(int levelNum)
     {
         texts = new List<TextAsset>();
         string label = levelNum.ToString();
 
         part1 = Addressables.LoadAssetAsync<TextAsset>("Assets/_Main/Animations/Content/" + label + "/t1.bytes");
         part2 = Addressables.LoadAssetAsync<TextAsset>("Assets/_Main/Animations/Content/" + label + "/t2.bytes");
         partData = Addressables.LoadAssetAsync<TextAsset>("Assets/_Main/Animations/Content/" + label + "/tData.json");
         part1.Completed += Part1Completed;
         part2.Completed += Part2Completed;
         partData.Completed += PartDataCompleted;
     }
     void Part1Completed(AsyncOperationHandle<TextAsset> asset)
     {
         if (asset.Status == AsyncOperationStatus.Succeeded)
         {
             texts.Add(asset.Result);
         }
     }
     void Part2Completed(AsyncOperationHandle<TextAsset> asset)
     {
         if (asset.Status == AsyncOperationStatus.Succeeded)
         {
             texts.Add(asset.Result);
         }
     }
     void PartDataCompleted(AsyncOperationHandle<TextAsset> asset)
     {
         if (asset.Status == AsyncOperationStatus.Succeeded)
         {
             texts.Add(asset.Result);
         }
     }
     //Form here you can do wherever yo want with the list of texts
 
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

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

Related Questions

How do I add a .c4d asset? 2 Answers

Built in shaders not available in unity 3.3 2 Answers

.assets file sizes 1 Answer

unity asset store 1 Answer

Write to XML-file within Assets\Resources 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