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 /
This question was closed Oct 09, 2019 at 08:10 PM by NMD83.
avatar image
1
Question by NMD83 · Aug 29, 2014 at 01:53 AM · prefabassetsloadingloadassetatpath

LoadAssetAtPath() returning null IN EDITOR

Hello,

I've searched and searched and mostly find people trying to use it for runtime stuff with builds and getting null.

Well, I'm getting null from within the editor. No play mode involved.

I have a static class which is used by a custom EditorWindow class. Everything in my editor works fine as far as saving, editing, etc. Except for loading in a prefab.

I have tried AssetDatabase and Resources. And both the typed and untyped versions of the Resources function. I also tried LoadMainAssetAtPath(). Have tried both with and without the .prefab extension. Have tried the full path, even the path without "Assets". Everything returns null.

I'm actually using the OpenFilePanel to get the path but have hardcoded it to be sure the path is indeed correct and for a better example.

I've tried every suggestion and everything I can think of and am hoping someone can tell me what's up.

The one thing I haven't tried, and I'm sure would work. Is a Resources folder and Resources.Load(). But I don't want or need these prefabs loaded or bundled at run time so LoadAssetAtPath() seems like exactly what I need but I can't make it work.

Unity Consoles 4.3.4f1

             GameObject temp1 = Resources.LoadAssetAtPath<GameObject>("Assets/[DragonBuilder]/NewDragon.prefab");
 
             GameObject temp2 = (GameObject)Resources.LoadAssetAtPath("Assets/[DragonBuilder]/NewDragon.prefab", typeof(GameObject));
 
             GameObject temp3 = (GameObject)AssetDatabase.LoadMainAssetAtPath("Assets/[DragonBuilder]/NewDragon.prefab");
 
             Debug.Log(temp1);
             Debug.Log(temp2);
             Debug.Log(temp3);


http://docs.unity3d.com/ScriptReference/Resources.LoadAssetAtPath.html http://docs.unity3d.com/ScriptReference/AssetDatabase.LoadAssetAtPath.html

Thanks!

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 graslany · Nov 26, 2014 at 08:49 AM 0
Share

All the things you do expect a GameObject to be returned. Have you tried not to cast it and find out whever it was a different type ? An instance of some other subtype of UnityEngine.Object for example ?

you could try something like this:

 Object[] allStuffPossiblyInTheAsset = AssetDatabase.LoadAllAssetsAtPath("Assets/[DragonBuilder]/NewDragon.prefab");
 if (allStuffPossiblyInTheAsset != null) {
   int nObjects = allStuffPossiblyInTheAsset.Length;
   Debug.Log(string.Format("Asset contains {0} object(s)", nObjects));
   foreach(Object obj in allStuffPossiblyInTheAsset) {
     Debug.Log(string.Format("Asset of type {0}: {1}", obj.GetType().ToString(), obj.ToString()));
   }
 } else {
   Debug.Log("Asset not found");
 }

1 Reply

  • Sort: 
avatar image
0

Answer by Chimique · Nov 26, 2014 at 11:03 AM

 GameObject temp4 = (GameObject)AssetDatabase.LoadMainAssetAtPath("Assets/[DragonBuilder]/NewDragon.prefab", typeof(GameObject));

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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Assets couldn't be loaded 1 Answer

Project moved - how to get back 1 Answer

How can I store and load levels efficiently? 2 Answers

Cannot find 3D Prefab after doing a build. 0 Answers

Lazy Loading and Unloading of prefabs? 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