Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Object field select menu can't find resources

Discussion in 'Editor & General Support' started by Miicck, Jun 17, 2020.

  1. Miicck

    Miicck

    Joined:
    Oct 16, 2014
    Posts:
    2
    I recently posted a question to answers.unity.com, which hasn't received any responses. Essentially, the problem boils down to the fact that I have a class that inherits from MonoBehaviour
    Code (CSharp):
    1. class item : MonoBehaviour
    2. {
    3.     // Stuff
    4. }
    And another class which references it
    Code (CSharp):
    1. class some_class : MonoBehaviour
    2. {
    3.     public item item_to_reference;
    4. }
    But, when I try to set item_to_reference from the inspector, the object picker window can't find the prefabs in the resources folder (specifically, I have items in resources/items, which don't show up).
    Any ideas?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    The object picker isn't as smart as you might hope. Sometimes you have to just find the thing manually in the project window and drag it in from there. I've found that if I've done that once, the prefab often starts showing up in the object picker after the first time.
     
  3. TomasKucinskas

    TomasKucinskas

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    60
    Hello, Miicck

    If you really want to use `MonoBehaviour` here, assigning references manually would probably be the only viable solution.

    On the other hand, I think your items may be represented using the `ScriptableObject` class as a base. This would allow you to have only the item data in the asset and enable your desired object picker behavior(I've checked it and the picker finds all of the items in the project if they are ScriptableObjects). See this page:
    https://docs.unity3d.com/Manual/class-ScriptableObject.html

    Hope this helps