Hi guys, i’m trying to save weapons gameobjects into a file. One way I was thinking, is by serializing (save) only the ID of the weapon created inside its ScriptableObject, and then deserialize it (load) that ScriptableObject in runtime. The problem is that I don’t know how to load ScriptableObjects from the assets. How can I get a ScriptableObject with a specific ID, and then load it by searching through all the ScriptableObjects in a folder? I was trying with the Resources folder, but it’s not recommended by unity and it wouldn’t work because I can’t access the ID variable inside the ScriptableObjects.
This is the script of the ScriptableObject:
[CreateAssetMenu(menuName = "ScriptableObjects/Weapon")]
public class WeaponDataSO : ScriptableObject
{
public string ID;
public GameObject WeaponPrefab;
public string Name;
public float Damage;
public float FireRateRPM;
public int MaxBulletsMagazine;
public bool SemiAuto;
public bool FullAuto;
public AudioClip ShootSound;
public enum WeaponTypes
{
Rifle,
SMG,
Pistol
}
public WeaponTypes Type = WeaponTypes.Rifle;
}