Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
0
Question by NPS · May 08, 2013 at 05:08 PM · assetresourcesexpose

Exposed asset variables vs Resources

I wonder when I should use which - when is it better to define many exposed variables like Texture and assign them in the Inspector and when it would be a better idea to use Resources. Any 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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by whydoidoit · May 08, 2013 at 05:34 PM

There are different schools of thought on this. My rule is this:

Load it from Resources only if you cannot have an inspector assigned reference. Example: I have a ScriptableObject that contains the version number of my app to match to the asset bundles on the server, I need to load this in script very early in a process and so I use Resources.Load so I don't have to be in a particular scene. I am probably going to try to remove this use of Resources.

Keep it in resources if it must be in your build. I use this for fall back shaders from Asset Bundles and other uses of shaders which are otherwise not included unless they are in a scene.

Here's why: everything in Resources is included in your project, including all of the stuff that you used to use but don't any more. If it's a scene reference and you changed it, no problem, it will be excluded. I just spent ages writing a pseudo resources script to remove the horrendous pile of junk added to my project by a third party supplied element where they'd put everything (including family member pictures which they were presumably using for testing) in Resources.

When you use Asset Bundles you can't load from Resources in them.

So my bottom line is this: don't use Resources if there is any other way of getting what you want. You are asking for trouble down the road.

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 whydoidoit · May 08, 2013 at 05:37 PM 0
Share

Just to clarify on that asset bundle thing.

If you use resources only in some scenes and you put those scenes into Asset Bundles you probably want to reduce the bloat caused by their resources. If the resources are in a Resources folder, it's in your build and not in your Asset Bundle.

avatar image Vonni · May 08, 2013 at 05:52 PM 0
Share

I have equipment in my game. Each equipment is a prefab in a resource folder. They need to be accessed from all scenes, for inventory, actionbars, offline customizing, actual in-game mechanics. They get loaded into an equipment Class. All the resources get loaded every time. Is there trouble down my road?

avatar image whydoidoit · May 08, 2013 at 06:01 PM 1
Share

So long as you are very careful to put that stuff in there then it's fine. What I do is have a standard scene I LoadLevelAdditive and put my shared components in that (Don't Destroy On Load their holder), but of course the approach you are taking is "ok", I wouldn't do it though because strings are fragile compared to my preferred approach of a script with well defined named variables assigned in the inspector.

$$anonymous$$g. if I want to change the "win" music or a sound effect I just open that scene and assign it, not start hunting for strings or rena$$anonymous$$g stuff.

avatar image Vonni · May 08, 2013 at 07:05 PM 0
Share

I start to see why you prefer your method, thanks!

avatar image
1

Answer by frarees · May 08, 2013 at 05:34 PM

Resources.Load will load Objects at runtime, and them can be loaded at any time (not precisely at scene load, so you can get faster loading times I presume). If those Object are referenced via inspector over Objects residing on a scene, they will be loaded the time the scene is loaded.

E.g. imagine a scenario where you need to choose between two atlas (high and low definition). Is best to load them via Resources.Load, as if you do via inspector both are going to be loaded.

Hope it helps.

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 whydoidoit · May 08, 2013 at 05:35 PM 0
Share

That's a good example of Resources.Load - presu$$anonymous$$g you don't have access to Asset Bundles which I'd use in preference.

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

15 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

Related Questions

GameObject permanent destruction from "Resources" in EditorWindow 0 Answers

Loading XML asset after build 0 Answers

Creating Assets On The Fly 6 Answers

Can't load prefabs from resources into an array 1 Answer

Manually changing between sprites in a spritesheet 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