Search Unity

Resolved How to reference a Collection in script

Discussion in 'Scripting' started by MinhocaNice, Apr 6, 2021.

  1. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    I am using ScriptableObject scripts to organize certain groups of objects in my game, and I ran into a problem. I have to always select the AssetMenu collection inside the editor to reference it in a script. I can't do that to all scripts because some of them are loaded in-game and I can't change their values unless inside the script itself.

    How do I make so the script searches for the AssetMenu in the assets folder to reference it?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    I'm not sure of your question... do you mean putting in something like this in the Project folder:

    t:AssetMenu


    ? That will work for ScriptableObjects but AFAIK it does not work for prefabs, even if they contain such a script.

    Or do you mean loading these at runtime, like with

    Code (csharp):
    1. var menus = Resources.LoadAll<AssetMenu>( "MyAssetMenusFolder/");
     
  3. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    I mean that I have
    public ExampleCollection CollectionScript = 
    and I want to know what to put at the other side of the equation.
     
  4. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    How do I make so it can load the whole collection from assets?
     
  5. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    Can it get the collection from files?
     
  6. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    How do I do this?
     
  7. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
  8. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    MinhocaNice likes this.
  10. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    MinhocaNice likes this.