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 arturo101199 · Aug 11, 2020 at 10:14 AM · texturescriptableobjectresources

Random textures, ScriptableObjects or Resources?

Hi, I am in a project where we generate random NPCs. The thing is that, for changing the texture i was using a ScriptableObject where i reference all posible textures of the character and then i choose one randomly. The problem is that now we can also change randomly the texture of a lot of other things, and i am watching that people usually use the resources folders for this kind of things, so should i stop using scriptableObjects with arrays of Texture2D references and start using the resources folder? What is the difference?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Azurelyte · Aug 13, 2020 at 06:15 AM

In my humble opinion, the answer is the enigmatic, "it depends". This is going to be more opinion than anything...


Texture References

If its only a few textures per thing, and you have the budget to keep all the textures in memory, then its fine. Having a list of referenced assets is an easy way to ensure that you don't run into issues with naming or loading the texture. However, once you reference your scriptable object in a scene with all those texture references, Unity will load them all and keep them in memory (even between stoping and starting play in the editor!). I tested this by referencing about 100 textures in a scene through a ScriptableObject and watched Unity eat up about 200mb of memory in the profiler. If these textures are constantly needed and you want to keep them around, this is a good option. If not, this is a terrible choice.


Resources

A better choice might be to load them out of the Resources directory. This way you can make use of the garbage collector to free stuff you don't need anymore. Especially for sets of things that are only used from time to time. One issue will be naming. You will need to enforce a naming scheme on the artists to avoid issues, and keep those strings in the scriptable object instead of Texture references. Your big benefit will be more control over assets and memory.


Streaming Assets/Other

There is a third option. You could pre-compress all of your textures and place them into the streaming assets folder OR ship the pre-compressed texture assets outside of unity all together and load them as needed using .net libraries and Texture2D.LoadRawTextureData(). The nice thing with this is that unity won't preform any hidden operations on those files, and you could potentially change these assets and push those changes to builds of the game without recompiling. Like with using the resources folder, you will need to take special care with your naming schemes. The big benefit here, is that you gain control over what format each texture is in and how its loaded. In my day job, we also use the build pre and post processes to cut assets out from being included to minimize the build size. It should be obvious that this requires a large time investment to make work.


So in summary and in my opinion...

  • Texture References == easy but less control and prone to gobbling up memory.

  • Resources == some control and minor annoyances to artists, but you should be able to manage memory better.

  • Streaming Assets == Gigantic pain to make work (especially on more than one platform) but you get the most control.

If this is just a small school project or quick prototype, I wouldn't worry, pick whatever is easiest for you and your artists. If your looking to ship a product and you want to provide the best experience possible, consider the latter options. The over arching difference is the amount of control that you get over the texture assets versus Unity. Though at the end of the day, your just dealing with different ways of loading data.

Comment
Add comment · Show 1 · 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 arturo101199 · Aug 13, 2020 at 08:54 AM 0
Share

Thanks man for that detailed answer, as i said to @Hellium i decided to try the addressable assets, I'm gonna try it, and see if i can make it work.

avatar image
0

Answer by Hellium · Aug 13, 2020 at 08:10 AM

To complete @Azurelyte 's answer, there is a 4th option: Unity Addressable Asset System.


Instead of having direct references to objects (your textures), you have their address. An address identifies the location in which something resides.


You have more control over the loading and unloading of the assets. Textures can be packed together so when you request one texture, you "pre-load" other textures. It can be useful if you are customizing a given object and you want to quickly switch between the textures it can have.

More info: https://docs.unity3d.com/Packages/com.unity.addressables@1.9/manual/index.html


Unity advises against using the Resources

3.1. Best Practices for the Resources System

Don't use it.

Comment
Add comment · Show 1 · 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 arturo101199 · Aug 13, 2020 at 08:49 AM 0
Share

In the time i posted this i researched a little bit, and i decided to use this, the problem is that the Documentation is not a really good and there isn't much info about ti, but im gonna try it.

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

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

into which folder can i import my jpeg files so i can put some texture on a wall obj? 0 Answers

Set texture / EnableKeyword not working in build 1 Answer

ridiculous load time using Resources.Load() on android build 0 Answers

Resources.LoadAllOfType With ScriptableObjects? 1 Answer

ScriptableObject , use Resources.Load sprite then it have error. 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