Pickup in Editor

I meant to ask this way back when… But why does Unity dislike trying to click the “browse” button when you are choosing the Pickup for an item/ability?

It is suuuuuuper annoying to have to my pickup folder and drag one in. I mean… not THAT annoying, but it is puzzling. I thought I had it worked out why from when I first took the course, but as I ramp this project up it is starting to grind on me and I have forgotten.

Pickup is a monobehaviour. I suspect going through all the prefabs in the project and recursively trying to resolve all components on them was not feasible and so the devs chose to not do it.

I am very confused on how they normally work then. I guess I am bad with the nuanced difference with something like this:

Check the tab. The ones you see there are in the Scene. If you switch to the Assets tab, I doubt you’d see any.

1 Like

Unfortunately, while ScriptableObjects can be selected from the assets (as well as things like sprites, textures, Animators), MonoBehaviours can’t be selected from the assets with the standard editor.
They can be selected from the assets with custom editors, or with tools like OdinInspector (paid asset).

As @bixarrio says, finding a MonoBehaviour is more complex than finding a standard asset because you have to load every single prefab asset in the game and then test it against the monobehaviour you’re looking for with GetComponent.

Here’s a trick that will let you load a Pickup and ensure that it’s a Pickup, though it won’t make selecting it any easier unless you include something like Pickup in the name:

[SerializeField] GameObject pickupGameObject=null;
[SerializeField] Pickup pickup=null;

void OnValidate()
{
    if(pickupGameObject==null) return;
    if(pickupGameObject.TryGetComponent(out Pickup testPickup))
    {
         pickup = testPickup;
    }
    pickupGameObject=null;
}

This will allow you to select any GameObject with pickupGameObject… When you click on this field, click the assets tab of the dialogue and type in pickup (you named all your pickups a variation of pickup, right?). Then select your desired pickup. OnValidate will then populate the pickup field correctly.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms