scriptable Objects Problems

Updated on May 9, 2018 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on April 5, 2018

I have been trying to load scriptable Object’s from within the code depending on what the player needs. I have created this Script as a template for creating different businesses that i want to add: 

[CreateAssetMenu(fileName = “New Business”, menuName = “Business/Service”)]
public class ServiceBusiness : ScriptableObject
{

//variables

}

I have created one named FastFood in order to test my code I have this in the main part of the game. 

public ScriptableObject[] businesses;
private ScriptableObject business;

void Start () {
     for (int x = 0; x < businesses.Length; x++){
          if (businesses[x].name == “FastFood”){
               business = businesses[x];
          }
     }

}

From unity i set the length of businesses and add the different businesses made with the script above. not sure how to get this to work, basically I want to have a bunch of these templates of businesses created and then depending on what the player wants it loads the correct template

  • Liked by
Reply
1 on May 8, 2018

hey man, its not good to answer a question with another question, but how cn i assign a scriptable object into a variable instead of drag and drop,

(https://www.youtube.com/watch?v=aPXvoWVabPY&t=1

thanks in advance

on May 9, 2018

if you put your scriptableobjects inside of a folder called “Resources”. you could then assign the reference to them with

var business = Resources.Load<ServiceBusiness>("Fastfood");
Show more replies
  • Liked by
Reply
Cancel
0 on May 8, 2018

I think your issue is that you declared your one ScriptableObject business, as private.

private ScriptableObject business;

Private and protected variables can’t be accessed by the editor. I think it might need to be this

public ScriptableObject business;

Here is a great series I just watched, from Unity, on Scriptable Objects; perhaps it might jar something loose? Customising UI With Scriptable Objects

Hope that helps.

  • Liked by
Reply
Cancel