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 paulaceccon · Apr 09, 2013 at 07:35 PM · wwwfilesfolderread

Open all files in a directory

Hi, I have a folder in my computer which has a lot of prefabs. I need to access then in one Unity project and instantiate some of these prefabs (according to the user's choice). I know that exists Resources.Load, but I can't use it. In fact, this folder is not static, so this prefabs may change and I opt for access a folder in my computer, but not in the Unity resources folder. So, I have to read all the prefabs in the folder and make then available. How could I do this? It would be using WWW?

Thanks.

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

3 Replies

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

Answer by Bunny83 · Apr 11, 2013 at 09:08 PM

The short answer is:
"Assets" in Unity can only have 4 different formats that can be read at runtime:

  • Assets built into the application. That are all the usual assets, no matter if referenced by a scene / script or if they have been placed into a Resources folder. All those assets are compiled into the application itself. They come with it and can't be used / accessed somewhere else. They are stored in a special format which can only be read by a Unity-player or the editor.

  • Assetbundles are external asset collection files which can be loaded at runtime from an arbitrary place you have access to (local file system, a webserver, ...). Assetbundles are a Unity pro feature. They have to be created within Unity.

  • External textures. You can load external textures with the WWW class and use WWW.texture to access it. Only the JPG and PNG format is supported.

  • MovieTexture. This is also a Unity pro feature. You can only load movies in the "Ogg Theora format". They can be loaded using WWW.movie

That's all Unity can access at runtime. You can not simply load an asset at runtime. Of course you can implement your own loader and your own custom data format, but Unity itself doesn't support loading any other assets out-of-the-box.

There are a lot third party solutions to save / load assets at runtime like the well known UnitySerializer

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 Sisso · Apr 11, 2013 at 09:40 PM 0
Share

Nice, good to know.... no magic here. You have destroyed my answer :P

avatar image
1

Answer by Sisso · Apr 09, 2013 at 07:48 PM

Resource is used only to read objects in our /Resource folder, that is automaticy embedded in your binary. You could use AssetBundle from Unity Pro or WWW.

My guess is that you need to do it in two steps.

First, access an already know url to fetch a list of prefabs. This could be a simple file or a complex json. You must put everything that user will need to make his choice, and the real url. You can easily generate it automatically from your prefabs inside Unity3d.

Second, load each selected prefab one by one using its real url. But like Bunny83 said, you will need a custom serialization because prefabs could not be loaded by WWW.

EDITED: Bunny83 confirm that you could not load prefab using WWW.

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

Answer by frarees · Apr 09, 2013 at 07:41 PM

AFAIK the only way to read GameObjects at runtime is by either referencing them via inspector, placing them into the hierarchy or searching them inside a Resources (sub)folder.

Is there any good reason not to use the Resources folder in your case?

Comment
Add comment · Show 5 · 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 Dracorat · Apr 09, 2013 at 07:49 PM 0
Share

If you want to "stage" files outside the Resources folder, there's no reason you couldn't copy IN TO the resources folder and then Resources.Load them after the copy completes.

avatar image paulaceccon · Apr 10, 2013 at 10:01 PM 0
Share

I have a project that has to access a directory in runtime, and I can add models to this directory and click on a button to reload all models in it. So I CAN'T have these models in to the resources folder, or I would have to make a new build every time a change occurs.

avatar image Dracorat · Apr 10, 2013 at 10:04 PM 0
Share

If I understand what you're saying, that's not true. You'd click refresh, see that there's new files in "remote directory", copy the new ones to "resources directory" and then use a resources load.

avatar image paulaceccon · Apr 10, 2013 at 10:15 PM 0
Share

So are you saying that I can copy these files to the resources folder in runtime? If so, it would be great, I didn't know that.

avatar image Dracorat · Apr 10, 2013 at 10:18 PM 1
Share

Yes - it'll require methods that are in the C# framework, not the Unity framework, but you have access to them through the 'System.IO ' namespace. Note that mobile platforms don't allow this type of manipulation (at all) but I don't suspect you're doing this sort of manipulation on mobile. I assumed PC.

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

14 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

Related Questions

Get list of all files in a directory? 3 Answers

Allow the player to use a custom music library? 2 Answers

accessing sub directory perhaps an crossdomain error 1 Answer

Is it safe to erase extra files when renaming project folder? 1 Answer

Using scripts out of my assets folder! 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