Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question How to create drag-drop slots on scriptable objects?

Discussion in 'Scripting' started by saltysquid, May 26, 2024.

  1. saltysquid

    saltysquid

    Joined:
    May 1, 2017
    Posts:
    43
    I have scriptable object items and scriptable object loot tables. I'd like to add items to the loot tables via drag-and-drop.

    If I create a scriptable object like this:

    Code (CSharp):
    1. [CreateAssetMenu]
    2.     public class LootTable : ScriptableObject
    3.     {
    4.         public List<ChestLoot> Items = new List<ChestLoot>();
    5.     }
    And ChestLoot is also a scriptable object - this works.... however, in the editor, if I enter 5 as the number of items in my Items list, I get 5 Chest Loot entries to fill out the data myself. What I want is 5 "slots" so I can click and drag my 5 scriptable object items into the loot table. I hope any of that made sense.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,369
    Hm, check your work because as long as
    ChestLoot
    is a ScriptableObject, you can create those files all day long and drag them into your Items[] array...

    Or am I not understanding what you're looking for?
     
  3. saltysquid

    saltysquid

    Joined:
    May 1, 2017
    Posts:
    43
    :rolleyes: - Apologies' - It seems ChestLoot was serializable (not scriptable) and I was supposed to be using an entirely other class called GameItem. Once I swapped that out I got the behavior I wanted!

    Thanks!
     
    Kurt-Dekker likes this.