Search Unity

End of the Resources folder

Discussion in 'General Discussion' started by Kiwasi, Oct 26, 2015.

  1. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    One of the key themes that permeated throughout Unite Melbourne was the general awesomeness of Asset Bundles. Pretty much every workshop I went to mentioned them.

    One of the devs from Obsidian went as far as mentioning that the Resource folder should never be used, and that asset bundles were the way to go. And that Unity had recognised this and was planning to deprecate the Resources system all together.

    So, was there a blog post I missed about the the deprecation? But anyway, I thought I'd start this thread as a last shout out to the Resources folder, and everything its done for us before we throw it ends up on the garbage heap of the Unity archive with SendMessage, the webplayer, OnGUI, flash builds and .ridgidbody.

    Thanks Resources. You were great. Say hi to OnGUI for me, we were buddies back in the day.
     
    KinanGH, ekhart and Noxzo like this.
  2. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    I've still never used Asset Bundles, I love my resources when it's needed (mainly) for Photon Networking.
    Never use it outside of that honestly.

    What makes Asset Bundles better than resources in general? I'm assuming speed efficiency.
    Looks like Photon gonna have to Upgrade from using Resources to Asset Bundles (however they are even done).

    Never used them so I don't even have a clue on where to start with using them lol.
     
    Aiursrage2k likes this.
  3. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I'd be happy if asset bundles rose up. I am using them for an experiment elsewhere and I love how they can important unity resources on the fly externally. If they move from resources to asset bundles then we knock out the model importing problem too.

    What's the current performance on importing asset bundles? I read a lot of scary things about them, and I don't want this to be another webgl.
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Internally, the Resources folder basically is an AssetBundle, it's just one that is generated automatically for you during the build process - but in a very inflexible way (no incremental build, no control over compression, no variant support, no ability to split into multiple bundles, files are required to be in a particular place in your project, etc).

    There's a few things AssetBundles are still missing, like script-free building, but once we've sorted all of those things out then Resources will just be 'a crappier AssetBundle' and we'll be looking to get rid of it. No timeline on this yet, though.
     
  5. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Except, Resource folder is very good for when you don't know whether you need something or not. Also dynamically spawning prefabs, having only resource name (string) as a way to get it. It's really useful, and I don't see I could live with asset bundles which are limited (resources folder can have any type of stuff, bundles only certain types).
     
    Gigiwoo likes this.
  6. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    You can do the exact same thing with AssetBundles.

    As far as I know that's simply not true; the resources folder is an AssetBundle so it wouldn't be possible for it to store something that can't be packed into an AssetBundle. Can you give an example of what you're talking about?
     
  7. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Custom binary data which I can store in Resources and load using textbytes or whatever it was called.
     
  8. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    That's supported by AssetBundles.
     
    angrypenguin likes this.
  9. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    How about not having to load it and just use Resources.Load instead of first loading asset bundle then using AssetBundle.LoadObject?
     
    Gigiwoo likes this.
  10. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    well, OK then. :)
     
  11. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Please provide API so us non-coders can use it please. :)
     
  12. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Good riddance, it always seemed a little hacky.
     
    landon912 and Kiwasi like this.
  13. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Is SendMessage being discontinued? I didn't find anything on that matter.
     
  14. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    I wouldn't thing so. Other unity elements like animation events rely on it.
     
    00christian00 likes this.
  15. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Resources.Load was only available via code. ;)
     
    KinanGH and theANMATOR2b like this.
  16. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    You just blew my mind.

    If I was able to figure this one out with a few minutes of research then it's not that bad :p

    I'm glad asset bundles are a priority. That's going to make modding a bigger part of unity games! I hope.
     
    Flickayy likes this.
  17. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,155
    How about implementing your own wrapper that replicates Resources but supports multiple AssetBundles? If you wanted it could even default to a specifically named bundle in the event that you don't specify the bundle's name.
     
    Last edited: Oct 26, 2015
  18. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    *holds my resource folder tight*

    Never let go resources... never let go...
     
  19. holliebuckets

    holliebuckets

    Moderator

    Joined:
    Oct 23, 2014
    Posts:
    496
     
    hippocoder, spryx, Tomnnn and 2 others like this.
  20. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    SendMessage is still around. But the job it did is mostly done by ExecuteEvents now. I don't see it disappearing entirely. But it's a lot less useful then it was.
     
  21. Megablaze

    Megablaze

    Joined:
    Oct 14, 2015
    Posts:
    30
    I'm glad you posted this, I'm still pretty new to unity, didn't know about asset bundles. I use resources because google searches threw me in that direction. I'll definitely look towards switching it out with asset bundles seeing as that seems to be the better option (based on this topic anyways).
     
  22. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Google is great. But it does have a habit of pushing old stuff and missing the newest features.
     
    Noxzo likes this.
  23. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Might just be my lack of understanding of AssetBundles, but to me they always seemed heavily tied into the concept of "downloaded" resources - i.e. you have them sitting on a server and steam them into your game when needed.

    The "Resources" folder was a local repository of assets that you load in on demand, when required.

    Do AssetBundles also function in that "local" sense as a direct replacement for the Resources folder?
     
    jakovd, darkhog and theANMATOR2b like this.
  24. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    melkior and darkhog like this.
  25. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    That was always my understanding too. However there seemed to be a lot of support for the idea of local asset bundles as well. The general idea was you could use local asset bundles as a more organised and controlled version of the resources folder.

    Tools like the asset manifest and variants seem to make the asset bundles a far more powerful option then the resources folder.
     
  26. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,021
    Same here. I have always assumed Resources was my local folder for spawning local prefabs through code and AssetBundles was for streaming/downloading assets on demand.
     
    darkhog likes this.
  27. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Yes, you can use them locally. Just point at a local folder. if you are doing a build that you are shipping, just have create folder that contains them and point to that. They are much more flexible in that regard. With Resources folder it is just all wrapped up in the build. If you have assetbundles, you can include them, but... you can also replace them. Without having to download a new client.

    For larger games, they can also be a huge benefit for development time and efficiency. For example in our architecture, we have many projects, one for all the key areas of assets (gui, character, environment, etc...) All game content is loaded via bundles. So the client project is very small, as all it contains is code. It runs fasts, builds fast and switching platforms is nearly instant. It never has to process assets. It also means that many people can be working on the game at the same time with no conflicts. If I am working on a character, I am in a project that only contains characters, and tools for build building characters. When I export, it creates a ios/android/webplayer assetbundle and stores in our cdn folders. Instantly anyone else running the client sees the changes. Other benefits include have multiple versions of assets for testing, having platform/device specific bundles. My last game we had "lowend" device bundles that were for old ipods/phones that lower poly, smaller textures and other optimizations. The client didn't care. You can't do that with resources folder. ;)

    Thats why I never got or found a use for the resources folder. The contents are not managed as well as real assets, yet they are not swappable or conditionally loadable like assetbundles. I do use them for prototyping and tooling, but found no good use for actual production.
     
  28. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Interested to know more on that if anyone has the answer. How do you reference and load "resources" from a locally stored AssetBundle?
     
  29. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    @zombiegorilla Ah! We posted at the same time :)

    Thanks for the explanation! Ignore my post asking for an explanation.

    EDIT: Actually, I'll add to this (not directed at anyone in particular) - so where is the documentation page that explains referencing them as a local path? Is it relative to the project root etc.
     
    theANMATOR2b likes this.
  30. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    People seem to think that a lot. I have never understood why. Maybe some tutorials show that way? Dunno.
     
  31. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    You do it exactly the same way as you would load them from a server, but you pass a local path as the url. So instead of :
    Code (CSharp):
    1.         string bundle_name = "coolGameStuff.assetbundle";
    2.         string bundle_path = "http://my_web_server/content/"+bundle_name;
    3.        
    4.          using (WWW www = new WWW(bundle_path))
    5.         {
    6.             // stuff...
    7.         }
    you would do:
    Code (CSharp):
    1.         string bundle_name = "coolGameStuff.assetbundle";
    2.         string bundle_path = "file:///"+Application.dataPath+"/../local_bundles/" + bundle_name;
    3.        
    4.          using (WWW www = new WWW(bundle_path))
    5.         {
    6.             // stuff...
    7.         }
     
    ZJP, Ryiah, Ony and 1 other person like this.
  32. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    http://docs.unity3d.com/ScriptReference/WWW.html

    It can be any local path, or use Application.datapath as a starting point if you want make it relative.
     
    Ony and Kiwasi like this.
  33. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    @zombiegorilla you da man, man. Thanks for the info - I'll experiment with that over the weekend.
     
  34. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    In the 4.x cycle asset bundles were a pro only feature. So the resources system was the only option free users had for managing dynamic assets that were not directly referenced in a scene.

    In the mad feature rush that occurred when we got everything in 5.0, I think many of us simply overlooked exploring asset bundles. I'm starting to be pleasantly surprised by their implications.
     
    zombiegorilla likes this.
  35. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Note that as well as using WWW, you can also use AssetBundle.CreateFromFile.

    This only works with uncompressed AssetBundles, but that's likely what you want anyway - they take up more disk space, but far less memory (only the 'index' of the bundle is loaded into memory when you create it, the actual resources are only loaded when you request them - as opposed to compressed AssetBundles which have to be fully loaded into memory). The Resources folder generates an uncompressed bundle as well so you shouldn't find that it uses any more disk space than before.

    Combine it with putting your asset bundles into the StreamingAssets folder, so that the bundles are automatically packed into your builds, and you've got yourself something that is very similar to the Resources folder but supports incremental building, more fine-grained control over loading and unloading, etc...
     
  36. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Yea, but I never saw a good reason to not reference them. Even then, textures and stuff were iffy on memory usage. And being in the project, everything still was processed, so there never seemed to be any real benefit (except for editor tools)
     
  37. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    On small projects like mine it was often convenient to build things by iterating through the contents of a resources folder. Say I was building a space invaders clone and had a bunch of different enemy types. I would simply throw the enemies all into a folder in resources and then randomly load them at run time. This made adding a new enemy trivially easy, simply wire up the prefab and drop in the enemies folder.

    Constraints like memory and processor speed don't really come into it on the scale that I build.
     
  38. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    But you still had to add the name to a list right? Or, iterate through the contents of the folder?
     
  39. Ony

    Ony

    Joined:
    Apr 26, 2009
    Posts:
    1,977
    I made heavy use of AssetBundles in one of my games I developed in Unity 2 then updated to Unity 3. The game has a content shop where users can buy extra content (characters, clothing, animations, etc.) then when they log into the game it automatically downloads their purchased content (in the form of asset bundles) to their local system where it stays. The game then loads that asset locally from then on. So, Asset Bundles was the perfect way to do this for my game.

    What's NOT so fun about Asset Bundles:

    We released that game in 2010 and it's still going today. We sold it to a new owner a little over a year ago but we contracted with him to continue to develop things for it (I'm actually working on an update as we speak. Unity 3... ugh). At one point I thought about upgrading the game from Unity 3 to Unity 4 (before 5 was out), but the way Asset Bundles work made me rethink that...

    Unity will only load an Asset Bundle that was made in the same Unity version as the game trying to load it. Asset Bundle loading is not backwards compatible, even with minor version updates. That meant I would have to pull everything up from backup, then recreate 40+ asset bundles containing hundreds of items, just so they would work. Then, if I updated Unity 4.x to Unity 4.y, I would have to do it all over again. From Unity 4 (onward, I believe), every update to the engine means rebuilding all of your Asset Bundles. Yeah. No thanks. It wasn't that way in Unity 3, because my Unity 3 game could load AssetBundles made in Unity 2. But, since 4.2 that is no longer the case.

    And because of that, I have not used Asset Bundles in any other games since that one. Having to rebuild a ton of Asset Bundles every time I update Unity (minor versions, not just major ones) is a big deal, and it's not worth it in my opinion to have to deal with it. So I don't even think about using them anymore.

    With all of that said, I don't believe I've ever used the Resources folder other than to hold some shaders that needed a place to stay so they'd be included in the build (again, Unity 3).
     
  40. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    @Ony Seems to be a pretty common thing for games anyway. New update breaks old 'mods'. I think users will be used to it and some day far in the future it may not even be a problem anymore.

    Or it could foster an ever changing environment of game models since new ones are always coming out and they have a chance to be noticed with all of the old ones being incompatible.
     
  41. Ony

    Ony

    Joined:
    Apr 26, 2009
    Posts:
    1,977
    It's not the users having to update their assets that is the concern, it would be me having to rebuild and upload a ton of asset bundles every time I needed to update to a new minor version of Unity. Given the current state of Unity 5 and the need to keep trying newer versions to fix engine bugs, that's not something I'd be very happy about having to do.
     
    Zinov, tatoforever and darkhog like this.
  42. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    Yeah, unless you figure out some way to set that up as part of a build pipeline, that would nothing but a nightmare.
     
    Ony likes this.
  43. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    So the deal with AssetBundles across Unity versions (and, indeed, multiple builds of your own game on the same Unity version) is this:
    • In order to load data from an AssetBundle successfully, Unity needs to know the serialised layout of the data so that it's able to interpret the data correctly. It can either use data about the serialized layout that is included in the bundle (a 'typetree') or it can use the serialised layouts of the classes it has built in.
    • Bundles built for Mobile and Console platforms don't include typetree information. (I'm asking other people why this is the case).
    • Bundles built for Webplayer always include typetree information.
    • Other platforms include typetree information by default, but you can disable it with a flag passed to BuildAssetBundles if you want.
    • If there's no typetree information, and the serialised layout of the classes in the bundle hasn't changed between builds of your game, then the bundles should still load OK. But, of course, you don't really want to rely on any particular class not changing between versions.
     
    Noxzo, zombiegorilla and Ryiah like this.
  44. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Yup. Additionally, this also means that you may need to have a way to distinguish bundles. So you can't just replace your bundles, as some users may have older clients. (though you can force client updates). We used to have folders with each version, and the client would point to its location. Now we just force an update to the client. (which is works out for the best for us anyway).

    While our whole pipeline is fully automated, and rebuilding every asset in the game is a single button click, with thousands of assets and multiple platforms, that button click still requires the better part of day to run. And human error is still a factor. Someone could have made a tweak to something outside the loop, and will get stomped by rebuild.
     
    Ony likes this.
  45. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I can see how that would be an issue if you were distributing through a $$$tiered$$$ system and you had fairly large asset bundles :eek:
     
    Ony likes this.
  46. Ony

    Ony

    Joined:
    Apr 26, 2009
    Posts:
    1,977
    Yup, we force a client update every time a new game build is released, about once every few months now. Forcing users to also wait while the game deletes then re-downloads all of their purchased assets would be... too much. A ton of them own every asset pack we've released over five years and I know they'd put up a fuss. The game is also set up to allow mods, so some people have content in multiple places and use third party mod programs to move it around when needed. It wouldn't be pretty. :)
     
    tatoforever and zombiegorilla like this.
  47. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Well really, it sounds like is all your own fault. If you made a less popular game that your users didn't enjoy, you wouldn't have to worry about keeping it updated. ;)



    Seriously, 6 years is pretty freaking impressive by any measure. Congrats on that!
     
  48. Ony

    Ony

    Joined:
    Apr 26, 2009
    Posts:
    1,977
    Haha too true. And thanks. :)
     
  49. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    A common workflow for me using prefabs is to:
    - Create the main script which will go onto the root object of the prefab.
    - Do whatever other config the prefab needs.
    - Stick it in Resources/Prefabs/WhateverCategoryItFitsIn
    - Adda static method at the top of its main script which loads the resource, instantiates the prefab, gets a script reference from the instance and returns it to me.

    It'd suck if the workflow for that got broken. I completely understand that the Resources folder is a bit... dodgy, and should be updated. I'd really like it if some compatible workflow was made available, though. (Personally, I've always liked the idea of setting properties for folders in a project and having it do nifty things with them at build time accordingly. Like "everything in here should be made into an AssetBundle accessible in the build" or "throw an error if anything in here is included in a build" and so on.)

    Another reason that workflow (or an equivalent) is critical:
     
    Ony likes this.
  50. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Is the unity version used to encrypt / hash something? Why is it so crucial to make these things unique?