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 /
avatar image
0
Question by Hirnfroster · Jan 18, 2017 at 12:40 PM · prefabspriteitems

Load Sprite and Prefab without Resources.Load

Hey guys!

I'm struggling a lot with my inventory system. I tried to optimize it when I found this article: https://unity3d.com/de/learn/tutorials/topics/best-practices/resources-folder

What I want to do is simply load a sprite and a prefab for my items into the scene. Here is an overview how I designed my item database:

Each item has a specific folder. Inside there is a .json file which contains the properties of this item. As well as a Sprite (for the inventory) and a prefab for the instantiation.

If you have a better idea for a database instead of folders, please present it here ;). I'd highly appreciate it!

But I don't want to have a plain array database*, since I want to implement quite a lot of items. Furthermore different item types have different properties, so only one database wouldn't be enough...

*By plain array database I mean something like: public Items[] itemDatabase;

Thanks in advance :D

Comment
Add comment · Show 1
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 EDevJogos · Jan 18, 2017 at 07:16 PM 1
Share

Well, i personally like "plain array" usually when is too much stuff i just make some subclasses and set everything on tree data structure, it makes it fast and easier to search for specific objects latter.

Insted of looking into the items as a single thing see if you can separate them into categories and make this categories into a class or sub class that inherit of item, then make arrays for each category of item.

Then you can have a tree of items with the main nodes being the categories, and if possible or needed make some more sub nodes with some other attribute.

So if you have like 200 items but only 10 of them are heavy you won't need to look through the entire array of items.

2 Replies

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

Answer by FortisVenaliter · Jan 18, 2017 at 07:09 PM

Well, if you don't want to set up references before runtime, you'll need to use the resources folder.

What I've done in the past is:

Set up a database script that can be used as a prefab. Store the data however it makes the most sense for you.

Write an editor script that allows the items to be dropped into a field that adds it properly to the database.

Use Unity's custom serialization to bake that complex dataset down to a simple array for saving to the disk. When you deserialize it on load, take the array you get and filter it out to your complex dataset.

An alternate way would be to use resources, and have a simple text file asset that lists all the prefabs to load. Then you can Resources.Load each one at load-time and put them into the appropriate place in your database.

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 Hirnfroster · Jan 20, 2017 at 08:47 PM 0
Share

Thank you guys :D I highly appreciate your answers. I think I'll go with the new 'plain array' kind of thing. If I split it into smaller pieces it is indeed a good solution. If I find another alternative I will update this topic.

The other solution with the serialization may be too difficult for me for now, but I will give it a try when I am more confident ;)

avatar image
0

Answer by Hirnfroster · Jan 21, 2017 at 06:50 AM

Thank you guys :D I highly appreciate your answers. I think I'll go with the new 'plain array' kind of thing. If I split it into smaller pieces it is indeed a good solution. If I find another alternative I will update this topic.

Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Resources not loading in APK 0 Answers

Display Item Sprite on Inventory UI 1 Answer

Changing the sprite of a prefab with in a script? 1 Answer

Network.Instantiate prefab with added parts 1 Answer

Editor Works, Build Not 1 Answer


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