• 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
Question by Rukas90 · May 06, 2018 at 09:03 PM · assetprefabsresourcesresources.loadmanagement

In-Game Resource Management (How to?)

Hello,

recently I've been working on the resource manager for my RTS game. I had looked on the internet for ideas and I found a way using Resource folder. It looks really easy and simple, but my only concern is safety. What if the user deletes the file or modifies it in some way. The asset file will be corrupted or will not be loaded because it does not exist anymore. That would break the game, if for example curtain unit could not be loaded. Or do I understand something wrong about this?

The thing I use now is Scriptable objects. I have two types of scriptable objects: "RecourceManager" and "Asset". The "Asset" is just a name of the object and a gameObject prefab reference. Inside the "RecourceManager" I have a list of "Asset" objects and everytime I want to get a reference of an object I call a function and pass a name of object I want to receive. Then inside that function I loop through all the assets list and check if the name I passed exists in the list of "Asset" objects. If so I return the prefab reference.

This way works fine, but the only downside is that I have to reference the "RecourceManager" everytime.
Is this even a good way of making something like this or are there any better ways?

Thank you!

Comment
iRayala

People who like this

1 Show 0
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

Answer by FlaSh-G · May 08, 2018 at 12:18 AM

The Resources folder will not exist in the game build. The only thing it does is protecting all the assets in it against build stripping, and making them available via Resources.Load. But assets in it are packed into asset files like all other assets. And if a user deletes or modifies one of those and the game stops working, it's really not your fault.

Concerning the approach - in my opinion, the Resources folder is extremely overused. It's nice to have if you need control over when exactly an asset is loaded or unladed, but people use it all the time without that need.

Instead of using the Resources folder, consider simply dragging things into fields of your MonoBehaviours. If you have a prefab, simply make a field of type GameObject, or even make the type a component the prefab must have. Then drag the prefab into your component using the inspector. Same goes for ScriptableObjects. Just make a field of whose type is your ScriptableObject-derived class and drag the object into it. The prefabs or ScriptableObjects will have been loaded before you use it.

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

86 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

Related Questions

Loading XML asset after build 0 Answers

Is there a way or an asset for managing assets that make up a prefab? 0 Answers

which is better : putting all files(Images, AudioClips, ...) in Resources and make one generic prefab ? OR make many Prefabs and instantiate them in Runtime ? and why?! 0 Answers

About to gut my use of the Resources folder. What are the best practices going forward? 1 Answer

Referencing prefab in code without using editor or Resources.Load? 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