I have a gamecontroller script that loads a base script with an override script depending on the current game mode…
function Awake ()
{
// Setup Mode Controller
modeController = gameObject.AddComponent("ModeController_"+currentArea.game.ToString());
}
The game mode script that will be spawned (“ModeController_Prevention”) holds a reference to a prefab (GraveController) that needs to be instantiated…
class ModeController_Prevention extends ModeControllerBase
{
var graveControllerPrefab : GameObject;
var graveController : GraveController;
function Start ()
{
// Create a GraveController for this round
var gc = Instantiate( graveControllerPrefab );
graveController = gc.GetComponent(GraveController);
}
}
When I run the scene direct, this all works perfectly and the ModeController script is attached and the GraveController prefab is instantiated. However when I’ve loaded my game’s Main Menu scene and then load this scene via that scene, the ModeController script gets attached correctly but the GraveController prefab is no longer there and results in the error, “The thing you want to instantiate is null.”