You can use CreateInstance or Instantiate. CreateInstance just needs the type, though, whereas Instantiate needs a reference.
If your goal was to use an array and get random SOs to assign, though, I don’t know if maybe you could just drag n drop them all from the inspector – that sounds even easier, unless there is some reason you feel differently.
Create a SO that have the array of all the possible SOs. Create a .asset in the Resources folder and drag and drop all SOs you want in the array (You can batch this using editor code). At runtime load the SO holding the array using
Stuff you talk about might be advaned to me for now :S
I made a simple script for example and the problem is in “MyMethod”
I thought that it should be very easy to swap “otherScript” var with referenced SO, does this make sense?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class cardDisplay : MonoBehaviour {
public card otherScript;
public Text nameText;
public Text infoText;
public Image avatar_sprite;
public ScriptableObject mojSO1, mojsSO2;
void Start () {
nameText.text = otherScript.myName;
infoText.text = otherScript.myInfo;
avatar_sprite.sprite = otherScript.m_avatar;
}
void MyMethod () {
otherScript.(this is where i need help) = mojSO1.(this is where i need help);
}
}
Instances of SO types are just assets on disk, you need to reference them somehow from amother SO or prefab, or put them in the resources folder and load them with Resouces.Load. Assets not in the resources folder that are not static referenced will not be included in build