• 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
1
Question by outpost75 · Dec 19, 2016 at 08:49 PM · scriptableobjectassetdatabase

AssetDatabase.FindAssets, how to use with namespaces?

I try to find my ScriptableObjects with AssetDatabase.FindAssets(filter, []folders).
They are found, as long as they are not in a namespace. If I use a namespace, they aren't found anymore, if the type is used as filter. I don't really understand how the filter is working, so I tried it with brute force. But that approach wasn't successful at all.

ScriptableObject, with namespace:

 using UnityEngine;
 
 namespace Franz.Item
 {
     public class ItemDefinition : ScriptableObject
     {
         public string ItemName = "Test";
     }
 }


ScriptableObject, without namespace:

 using UnityEngine;
 
 public class ItemDefinition : ScriptableObject
 {
     public string ItemName = "Test";
 }


This is what I tried to find the ScriptableObjects:

     var AssetDirectory = "Assets/Items";
     var assetPaths1 = AssetDatabase.FindAssets("*", new[] { AssetDirectory });

     var assetPaths2 = AssetDatabase.FindAssets("t:ItemDefinition", new[] { AssetDirectory });
     var assetPaths3 = AssetDatabase.FindAssets("t:Item.ItemDefinition", new[] { AssetDirectory });
     var assetPaths4 = AssetDatabase.FindAssets("t:Franz.Item.ItemDefinition", new[] { AssetDirectory });
     var assetPaths5 = AssetDatabase.FindAssets("t:" + typeof(ItemDefinition), new[] { AssetDirectory });

     var assetPaths2A = AssetDatabase.FindAssets("t:'ItemDefinition'", new[] { AssetDirectory });
     var assetPaths3A = AssetDatabase.FindAssets("t:'Item.ItemDefinition'", new[] { AssetDirectory });
     var assetPaths4A = AssetDatabase.FindAssets("t:'Franz.Item.ItemDefinition'", new[] { AssetDirectory });
     var assetPaths5A = AssetDatabase.FindAssets("t:'" + typeof(ItemDefinition) + "'", new[] { AssetDirectory });

     var assetPaths2B = AssetDatabase.FindAssets("t:\"ItemDefinition\"", new[] { AssetDirectory });
     var assetPaths3B = AssetDatabase.FindAssets("t:\"Item.ItemDefinition\"", new[] { AssetDirectory });
     var assetPaths4B = AssetDatabase.FindAssets("t:\"Franz.Item.ItemDefinition\"", new[] { AssetDirectory });
     var assetPaths5B = AssetDatabase.FindAssets("t:\"" + typeof(ItemDefinition) + "\"", new[] { AssetDirectory });


  1. Test scenario: ScriptableObject with namespace
    assetPaths1 found the ScriptableObjects.
    The other filters returned 0 results.

  2. Test scenario: ScriptableObject without namespace
    assetPaths1, 2, 3, 4 and5 found the ScriptableObjects.
    The filters with A and B suffix returned 0 results.

I can imagine why assetPaths1 could find results in both scenarios.
I can imagine why assetPaths2 could find results in the 2. scenario.

I don't understand why assetPaths3, 4 and 5 found results in the 2. scenario.

From the documentation:

The filter string can contain search data for: names, asset labels and types (class names).

So my filter with "type" is actually a filter with "class name"?
But what happens with the dots?
And why doesn't it work with namespaces? The class name didn't change.

My workaround for now: Hoping that I don't put something in the Items folder, that is not an ItemDefinition.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by CurlyTail · Jul 28, 2017 at 04:05 AM

I ran into the same problem, for nested namespace the FindAssets couldn't find any object, after digging a little bit and this is how I fixed it,

I renamed all scriptable object to exactly the class name, by doing this, Unity could find them again, then i change the name back to original name and it still working.

I have no idea what's going on but this trick fix the problem, Just thought it might help someone.

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.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom assets give Missing (Mono Script) 0 Answers

Can I save a ScriptableObject holding data from a private database class without [SerializeField]? 1 Answer

ScriptableObject.CreateInstance(Type T) keep crashing 2 Answers

How to change an object's name inside an asset file? 0 Answers

AssetDatabase.LoadAssetAtPath() doesn't always work 4 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