- Home /
Variable nos assigned on inspector, but it has been assigned on inspector ?
I'm trying to instantiate a object, getting data from a "GameAssets" script that i created, i made this already before, so i find strange getting this problem now. Here's my code:
public class Spawner : MonoBehaviour {
void Start()
{
Transform player = Instantiate(GameAssets.GetInstance().player, Vector3.zero, Quaternion.identity);
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class GameAssets : MonoBehaviour {
private static GameAssets instance;
private void Awake()
{
instance = this;
}
public static GameAssets GetInstance()
{
return instance;
}
public Transform player;
public Transform fish;
}
Thing is, the variables are being assigned on the inspector with no problem, they are the prefabs and there are no other version of them existing on the project, there have been no alterations on them after i assigned them neither, so i'm kinda stuck here.
I Run some tests and yeah, the player/fish are being null at the start, but i don't get why if they are assigned on the inspector. Can anyone help out?
The likely cause is that you have more than once instance of your GameAssets class in the scene.