Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Loading Scriptable Objects

Discussion in 'Editor & General Support' started by rahulkamra, Sep 17, 2016.

  1. rahulkamra

    rahulkamra

    Joined:
    Aug 16, 2013
    Posts:
    15
    Hi guys,

    I want to load the scriptable objects from the hard drive and i don't want to put them in the resources or steaming folder. Is there any way i can load them?

    Thanks.
     
  2. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,986
    You just reference them in your class as a public variable.
     
  3. rahulkamra

    rahulkamra

    Joined:
    Aug 16, 2013
    Posts:
    15
    Thanks for the reply , what I meant was that I have a .asset file which I want to put it outside unity and load it on the runtime.
     
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,986
  5. rahulkamra

    rahulkamra

    Joined:
    Aug 16, 2013
    Posts:
    15
    I tried to load the Scriptable Object .asset file using the asset bundle api but it failed as it is not an asset bundle. Do i need to convert them in asset bundle first or any other way i can load them

    Thanks
     
  6. mikael_juhala

    mikael_juhala

    Joined:
    Mar 9, 2015
    Posts:
    247
    The link zombiegorilla gave explains all that.
     
  7. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,171
    Like this:

    Code (CSharp):
    1. SlotDataAsset slot = UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(SlotDataAsset)) as SlotDataAsset;
    Note that this can only be done in the editor.
     
    tokar_dev, dregan and MD_Reptile like this.
  8. rahulkamra

    rahulkamra

    Joined:
    Aug 16, 2013
    Posts:
    15
    Thanks Jaimi for the reply , but I want to load them in the game , not in editor , can I load them without using asset bundles?
     
  9. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,986
    No. You will need to put it into an assetbundle and then load the assetbundle.
     
    FoxsterDev likes this.
  10. rahulkamra

    rahulkamra

    Joined:
    Aug 16, 2013
    Posts:
    15
    Thanks a lot guys , i will do a test :)