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 /
  • Help Room /
avatar image
0
Question by Vattalus · Jun 14, 2016 at 07:14 PM · assetruntimeloadingfast

How to store LOTS of game assets to QUICKLY find and load in runtime

Hello,

Short Desc
I'm working on a medium to large scale RTS style game in which i will need to store dozens if not hundreds of meshes, textures, sprites etc (units, weapons, icons, skills, items etc).

Requirements
Say I want to store a list of units, each has some atributes (hp, atk, etc) and models/textures, sprites. If Im looking for a specific unit, the system needs to quickly find and retrieve it. But i'll also need to load all of them to do some filtering or whatever. Kind of like a database, but stored locally in unity.

My Implementation so far / Ideas to improve existing solution
Currently, i have a Scriptable Object that stores all the unit's stats, reference to the prefab with meshes/textures, sprites in a Resources folder. Each unit has a unique ID , then if i want to load a specific unit by ID, i first need to load ALL my units, check their IDs, then return the one with the correct ID. Problem is, buy doing this, the game has to load ALL the models, textures etc associated with all the units, which is less than ideal.

My idea for improving this would be to only store lightweight data (ids, names, descriptions, stats) in a ScriptableObject, so when looking through all my units, i only have to load some ints, strings...maybe an icon. But also store a string containing the location of the heavy data (meshes, textures) also in the Resources, but separately. This way, i can also load the actual prefab when i find the correct unit in the list.

This would probably work fine, but i imagine it seems rather messy and inelegant. There has to be a better way of doing this... How do huge RPGs or MMOs do it? Any suggestions?

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

Answer by agray427 · Jun 14, 2016 at 08:08 PM

Well, you could store each unit's (or whatever else's) data as an individual scriptable object (in separate folders to keep it clean) and then have a scriptable object with a dictionary and pass in the id and have it return the path to the data you're requesting. I'm not sure if you have a resource database or if you have a database for each type of resource, but that would allow you to only search through a very lightweight dicitionary. If you want to further your question, I can try to think of something else, but this is what I would recommend.

Edit: The dictionary of course would have the key be whatever type you're using for the ID and the value be a string for the path.

Comment
Add comment · Show 4 · 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 Vattalus · Jun 15, 2016 at 06:08 AM 0
Share

Yes, this is similar to what i had in $$anonymous$$d, but i was thinking if there was a radically different / better solution to my problem. Thanks for the answer though, you gave me an idea, if nothing else, i'll use a dictionary solution

avatar image agray427 Vattalus · Jun 15, 2016 at 06:50 AM 0
Share

I made a quick example of what you could do. Unfortunately, Unity doesn't let you edit a Dictionary in the Inspector... Nor does it let you edit a $$anonymous$$eyValuePair. So what you need to do is create a class that acts like a $$anonymous$$eyValuePair and store it within a list. This is just for editing. Then you will translate that over to the Dictionary so you can do the $$anonymous$$ey search.

Alternatively, $$anonymous$$icrosoft does have its source code for a dictionary out on the Web. If you want to create your own class, a "Database" perhaps, that has the same functionality concepts of a dictionary, I recommend looking at that.

 using UnityEditor;
 using UnityEngine;
 using System.Collections.Generic;
 
 [CreateAsset$$anonymous$$enu(fileName = "Database", menuName = "Create Database", order = 0)]
 [System.Serializable]
 public class Database : ScriptableObject
 {
     [SerializeField]
     private List<Entry> entries;
     private Dictionary<string, Item> items;
 
     public Dictionary<string, Item> GetDictionary()
     {
         if (items.Count != entries.Count)
         {
             items = new Dictionary<string, Item> ();
             foreach (Entry entry in entries)
             {
                 items.Add (entry.$$anonymous$$ey, entry.Value);
             }
         }
 
         return items;
     }
 
     [System.Serializable]
     public class Entry
     {
         public string $$anonymous$$ey;
         public Item Value;
     }
 }
 
 [System.Serializable]
 public class Item
 {
     public string Name;
     public int Value;
 }

I hope this helps you out. If you have any further questions or would like more functionality than what I have provided, leave another comment.

avatar image Vattalus · Jun 15, 2016 at 06:23 PM 0
Share

Yeah, using a dictionary is a pretty good solution.

I asked this question because i was wondering if there were other methods of storing/loading assets. Something built into Unity, or i dunno :P

Thanks for your time, i'll wait if anyone else has other suggestions, if not, ill mark this as an answer

avatar image ddk4113 · Oct 27, 2016 at 06:42 AM 0
Share

@agray427 how to add entries via the script usin gyour code?

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

61 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

Related Questions

Assets won't load 0 Answers

Best way to let player manage assets in runtime ? 1 Answer

What is the best solution to load models at runtime? 1 Answer

Dynamically Loading Unity Content Without Publishing App Store Update 1 Answer

SceneManager.LoadSceneAsync is only working once 2 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