Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    4
    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:
    4,786
  3. PedroPoni

    PedroPoni

    Joined:
    Jun 21, 2017
    Posts:
    4
    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?
     
unityunity