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
2
Question by Aleron · Jan 16, 2012 at 09:31 PM · objectpathfolderselectprogrammatically

Get UnityEngine.Object reference to folder in project from folder path

I've looked all over in the documentation and online resources for a way to get the Object reference to a folder in my project when I have the path of the folder (relative to the project). I'm attempting to automate the building of several asset bundles, some of which are based on folder hierarchy rather than being in a scene. Building an asset bundle for a folder is easy enough to do, if based on manually selecting the folder within the project window. However, I can't seem to find a way to take the relative path (e.g. "Assets/Bundles/Shared Files") and get a reference to an Object (like that return from Selection.activeObject) using the Unity API.

Does anyone know of a way to get such a reference? Or even a way to set the selection based on the path within the project rather than already having a reference to an Object?

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
Best Answer

Answer by Jessy · Jan 16, 2012 at 10:14 PM

http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.LoadAssetAtPath.html

You mentioned a folder, not a file, so...? http://msdn.microsoft.com/en-us/library/system.io.directory_methods.aspx

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 Aleron · Jan 17, 2012 at 05:07 PM 0
Share

Now I feel silly. I thought I had already tried using those methods on AssetDatabase and failed to get a Unity Object back for folders. I ended up using AssetDatabase.Load$$anonymous$$ainAssetAtPath. Thanks! :)

avatar image wrxmarcus · Dec 21, 2012 at 01:23 AM 0
Share

Aleron - great question. This is exactly what I'm trying to do. I've been trying to use Load$$anonymous$$ainAssetAtPath, but have not been successful. Would you by chance have some sample code that you got working to generate multiple asset bundles based on directories?

avatar image Mambo4 · Sep 30, 2015 at 01:42 AM 0
Share

LoadAssetAtPath(string assetPath, Type type);

What value for "type" do I pass to this function if the object in question is a folder?

avatar image Bunny83 Mambo4 · Sep 30, 2015 at 02:09 AM 0
Share

I never was in need to get an object reference for a folder in Unity. However if it's still possible you might want to try typeof(UnityEngine.Object).

avatar image
0

Answer by idbrii · Aug 23, 2018 at 06:30 PM

Jessy's answer and comments collapsed into a solution:

 AssetDatabase.LoadAssetAtPath<UnityEngine.Object>( "Assets/Scripts/Game"));

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

9 People are following this question.

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

Related Questions

select all objects in the hierarchy of an object 1 Answer

Selecting Random Object and Setting Variable to True 2 Answers

Move selected object. 1 Answer

Make objects follow main objects exact path. 1 Answer

AssetDatabase current folder? 2 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