Instantiate problems

HI, i try to instantiate an object from another scene, but the object never showed up because NullReferenceException

so basically i have 2 scene, CharSelection and GameWorld.
here’s the code that link them

this is CharacterSpawn.js that i attach to “GameWorld”, MainCamera

var playerMale : GameObject;
var playerFemale : GameObject;

var savedplayer : int = 0;

	function Awake () {
		savedplayer = PlayerPrefs.GetInt("selectedplayer");
		
		playerMale = GameObject.Find("Cube1_M");
		playerFemale = GameObject.Find("testchar_F");
		
		if(savedplayer == 1){
			Instantiate(playerMale, Vector3(2,2,2), Quaternion.identity);
			playerFemale.SetActive(false);
			gameObject.AddComponent("PlayerStats");
			
		}
		else if(savedplayer == 2){
			//Instantiate(playerFemale, Vector3(0,0,0), Quaternion.identity);
			playerMale.SetActive(false);
			//playerFemale.SetActive(true);
			gameObject.AddComponent("PlayerStats");
		}
	}

this is ChangeChar.js attached to option button on “CharSelection”

var isMale = false;
var isFemale = false;
var selectedplayer : int = 0;

function OnMouseUp() {

	if(isMale == true) {
		PlayerAttributes.player_gender="Male";
		print(PlayerAttributes.player_gender);
		GameObject.Find("Cube1_M").transform.position.x = -1.7;
		GameObject.Find("testchar_F").transform.position.x = -7;
		selectedplayer = 1;
		PlayerPrefs.SetInt("selectedplayer", (selectedplayer));
	}
	if(isFemale == true) {
		PlayerAttributes.player_gender="Female";
		print(PlayerAttributes.player_gender);
		GameObject.Find("Cube1_M").transform.position.x = -7;
		GameObject.Find("testchar_F").transform.position.x = -1.7;
		selectedplayer = 2;
		PlayerPrefs.SetInt("selectedplayer", (selectedplayer));
	}

}

when i Instantiate i need playerMale as an GameObject.Find (the object to instantiate)
but the GameObject.Find() need the object on the scene to point, and because my object was on CharSelection scene, it shows an error, which is NullReferenceException…

is there any way out of this loop?

If it’s a template GameObject that’s always the same, I’d suggest referencing a Prefab. They’re game objects that are saved in the file hierarchy. You can assign them to GameObject references in the inspector like scene GameObjects. Their purpose is specifically to have Instantiate() called on them.

If it’s a unique character that was created at runtime from another scene before the new scene was loaded, you could use DontDestroyOnLoad() on the GameObject. From there you can either call Instantiate() on it, or just reuse that existing GameObject that was created - but not destroyed - from the previous scene(s).