Search Unity

Get a reference to a ScriptabeObject at runtime

Discussion in 'Scripting' started by PedroPoni, Jul 2, 2020.

  1. PedroPoni

    PedroPoni

    Joined:
    Jun 21, 2017
    Posts:
    5
    Hi there,

    I've this ScriptableObject:

    Code (CSharp):
    1. [CreateAssetMenu]
    2. public class InventoryItem : ScriptableObject
    3. {
    4.     public Sprite sprite;
    5. }
    and I've created some InventoryItem assets.

    Now I need to know how can I get a reference to one of the assets at runtime having the asset name?

    I know I can get a reference by dragging it to a public field in a MonoBehaviour but in this case I want to get the reference knowing the asset name.

    Is that possible?

    Thanks.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
  3. PedroPoni

    PedroPoni

    Joined:
    Jun 21, 2017
    Posts:
    5
    I think I will use both:

    Resourses folder for prototyping and Addressables for production.

    Thank you for your help!

    PD: By the way is there a way to mark your answer as the accepted answer or the post as solved?