0
\$\begingroup\$

When setting a variable for an object in Unity, for built-in types there is an option on the right-hand side to bring up a dialog that lists the possible values that can be chosen for that variable, for example when selecting a Sprite for a Sprite Renderer:

Sprite Renderer Select Sprite dialog

Is it possible, and if so what do I need to do, to have that list populated with the prefabs within my project?

Item Randomiser Empty Item dialog

In this example, there are a number of Item prefabs (both inside and outside the Resources folder if that makes a difference), however they do not appear in that dialog. Is there an attribute I am missing that needs to be specified on the Item class, or something else to enable this?

Example Item prefab

using UnityEngine;
using System.Collections.Generic;

public class Item : MonoBehaviour, IIdentifiable, IFilterable
{
    [SerializeField]
    private int IdField;
    [SerializeField]
    private bool ActiveField;

    public int Id => IdField;
    public bool Active => ActiveField;
}


public class ItemRandomiser : MonoBehaviour, IWeightedObject
{
    [SerializeField]
    private List<string> NamesField;
    [SerializeField]
    private List<Item> ItemTemplatesField;
}
\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Your Item is not an asset, it's a component. That dialog shows ASSETS of its type.

If you change List<Item> to List<GameObject>, you will see all the prefab assets in your project.

Or instead if you change Item from being a MonoBehaviour to being a ScriptableObject, then that dialog will show all the Item assets you created in your project.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .