How to instantiate my ScriptableObject on Scenario
Hi all, I have an 3d scenario and I want to instantiate and deploy them on my map. I use Scriptable Objects to create an template
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Airport", menuName = "Airport")]
public class AirportTemplate : ScriptableObject
{
public string airportName;
public int startingOperationsAt;
public string icao;
public string iata;
public int runway;
public float latitude;
public float longitude;
public long passengerRealDemand;
public long cargoRealDemand;
public int passengerRealDemandDate;
public int cargoRealDemandDate;
}
I want to put this assets on my Scenario
I do an class to Instantiate all this airports at start Scenario, but how can I Instantiate and put the sprites on my scenario
Answer by valentingurkov · Mar 01, 2020 at 07:58 AM
One thing that comes to mind is loading them via var someting = Resources.Load<AirportTemplate>(path/from/resources/yourObject);
https://docs.unity3d.com/ScriptReference/Resources.Load.html
This will establish a reference that you can use to read the data. And if you really want to instantiate it with another copy in memory (modifying it won't modify the scriptable object you have on disk), after the loading you can instantiate it like any other game object e.g. var copy = Instantiate(something);
Hope this helps.