- Home /
How Do you find a Rescourses.Load object in another script.
Allright so , before i begin i want to let you know i'm a complete newby to C# and unity. I am making save and load buttons in my scenes. In the GameScene itself (where all the data is located i need to save and load) it works. But when i run it from the MainMenu scene it doesnt load since the correct objects aren't here . so what i do is : if my current scene is not the GameScene it does Scenemanager.Load and then runs the normal load function , it doesnt work since the playername is found on a non destroy on load object that comes from the second scene (scene between Main Menu and GameScene) , so what i did was add the object to a rescourse folder and load it into the scene when a bool is true and it puts it on true when i come from the mainmenuscene to the Gamescene.
So now there is the object that has the name in it in the correct scene but when i do Gameobject.Find("loadedobjects name") it returns null
I am rly bad at explaining so perhaps code will help I know this is alot of stuff to look into but please, ive been stuck for some time on this :/
script that loads the object that has name in it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine.SceneManagement;
public class LoadGameObject : MonoBehaviour
{
public GameObject NameDataHolder;
public LoadAll LoadAllScript;
private void Start()
{
LoadAllScript = GameObject.Find("Dataholder").GetComponent<LoadAll>();
if (LoadAllScript.MainScreenLoadBool == true)
{
LoadObject();
}
}
public void Update()
{
}
public void LoadObject()
{
NameDataHolder = Resources.Load("Objects/NameDataHolder") as GameObject;
NameDataHolder = GameObject.Instantiate(NameDataHolder);
NameDataHolder.name = "NameDataHolder";
}
}
Load script (function set to a button on GameScene and MainMenuScene
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine.SceneManagement;
public class LoadAll : MonoBehaviour
{
private TextController textControllerScript;
private NameSelectTest nameSelectTestScript;
public GameObject NameDataHolder;
public bool MainScreenLoadBool;
public void LoadAllFunction()
{
if (GameObject.Find("NameDataHolder") != null)
{
LoadAllLoadFunction();
Debug.Log(MainScreenLoadBool);
}
else if (GameObject.Find("NameDataHolder") == null)
{
GameLoadScene();
MainScreenLoadBool = true;
}
}
private void GameLoadScene()
{
SceneManager.LoadScene("Game");
}
private void LoadAllLoadFunction()
{
textControllerScript = GameObject.Find("TextControllerText").GetComponent<TextController>();
nameSelectTestScript = GameObject.Find("NameDataHolder").GetComponent<NameSelectTest>();
textControllerScript.Load();
nameSelectTestScript.Load();
}
}
GameScript in GameScene that needs the playername from the null returning object if loaded from MainMenuScene
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine.SceneManagement;
public class TextController : MonoBehaviour
{
public Text text;
public Text nameText;
public List<string> States;
public string myState;
public BackgroundController backgroundScript;
public string playerName;
public string textstring;
public int background;
public string currentSceneName;
public GameObject NameDataHolder;
public NameSelectTest nameSelectScript;
public LoadAll LoadAllScript;
public SaveAll SaveAllScript;
// Use this for initialization
void Start()
{
myState = "Wakeup";
backgroundScript = GameObject.Find("GameBackground").GetComponent<BackgroundController>();
nameSelectScript = GameObject.Find("NameDataHolder").GetComponent<NameSelectTest>();
LoadAllScript = GameObject.Find("Dataholder").GetComponent<LoadAll>();
SaveAllScript = GameObject.Find("Dataholder").GetComponent<SaveAll>();
playerName = nameSelectScript.playerNameInherit;
Debug.Log("bool: " + LoadAllScript.MainScreenLoadBool);
if (LoadAllScript.MainScreenLoadBool == true)
{
LoadAllScript.LoadAllFunction();
}
}
// Update is called once per frame
void Update()
{
text.text = textstring;
print(myState);
if (myState == "Wakeup")
{
WakyWaky_01();
}
else if (myState == "Wakeup_02")
{
WakyWaky_02();
}
else if (myState == "Wakeup_03")
{
WakyWaky_03();
}
else if (myState == "Waytoschool_01")
{
WayToSchool_01();
}
else if (myState == "Hit_01")
{
Hit_01();
}
else if (myState == "Hit_02")
{
Hit_02();
}
else if (myState == "Hit_03")
{
Hit_03();
}
else if (myState == "Hit_04")
{
Hit_04();
}
else if (myState == "Waytoschool_02")
{
WayToSchool_02();
}
else if (myState == "Waytoschool_03")
{
WayToSchool_03();
}
else if (myState == "Arriveatschool_01")
{
ArriveAtSchool_01();
}
else if (myState == "Arriveatschool_02")
{
ArriveAtSchool_02();
}
else if (myState == "Arriveatschool_02_1")
{
ArriveAtSchool_02_1();
}
else if (myState == "Arriveatschool_03")
{
ArriveAtSchool_03();
}
else if (myState == "Arriveatschool_04")
{
ArriveAtSchool_04();
}
else if (myState == "Arriveatschool_05")
{
ArriveAtSchool_05();
}
else if (myState == "Arriveatschool_06")
{
ArriveAtSchool_06();
}
else if (myState == "Arriveatschool_07")
{
ArriveAtSchool_07();
}
else if (myState == "Arriveatschool_08")
{
ArriveAtSchool_08();
}
else if (myState == "Bell")
{
Bell();
}
}
void WakyWaky_01()
{
backgroundScript.ChangeToRoom();
nameText.text = playerName.ToString();
textstring = "*Yawn* \"Another morning, another day. Well! Time to get up!\" " +
"as i struggle out of my bed to go brush my teeth i hit my toe, *lets out a frustrated grunt*\n\n ";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Wakeup_02"; }
else { }
}
void WakyWaky_02()
{
backgroundScript.ChangeToRoom();
nameText.text = playerName;
textstring = "\"Nope fuck this!\" i get into my bed again and rest some more. \n\n";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Wakeup_03"; }
else { }
}
void WakyWaky_03()
{
backgroundScript.ChangeToRoom();
nameText.text = playerName;
textstring = "My alarm goes off again. I look at the clock: 5 more minutes till school. " +
"\"OH CRAP I GOTTA HURRY!!\" I quickly put on my clothes and leave the house.";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Waytoschool_01"; }
else { }
}
public void WayToSchool_01()
{
nameText.text = playerName;
backgroundScript.ChangeToStreetIMG();
textstring = "\"I hope i can make it in time for the attendence check!\"" +
"\n\n *insert screen shake here*";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Hit_01"; }
else { }
}
void Hit_01()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "\"Auw...\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Hit_02"; }
else { }
}
void Hit_02()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = "?????";
textstring = "\"Hey ! W-w-watch where you're going !\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Hit_03"; }
else { }
}
void Hit_03()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "\"S-Sorry!\" ";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Hit_04"; }
else { }
}
void Hit_04()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "I quickly get back up and continue running to school.";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Waytoschool_02"; }
else { }
}
void WayToSchool_02()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "I kinda feel sorry for her ... , it doesn't look like she's not around here either...\n" +
"Makes me wonder...";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Waytoschool_03"; }
else { }
}
void WayToSchool_03()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "Well... whatever. I'm sure it's not a big deal.";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_01"; }
else { }
}
void ArriveAtSchool_01()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "I finally arrive at school, looks like i actually made it fairly in time.";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_02"; }
else { }
}
void ArriveAtSchool_02()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = "?????";
textstring = "\"Ooooyy~ !!!\" \" " + playerName + "~ !!!\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_02_1"; }
else { }
}
void ArriveAtSchool_02_1()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "\"Huh ?\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_03"; }
else { }
}
void ArriveAtSchool_03()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "Ah... there he is, Randel , my personal stalker, he who sees me as a valuable friend while i have never even done anything for him...";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_04"; }
else { }
}
void ArriveAtSchool_04()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = "Randel";
textstring = "\"You've heard the rumors haven't you ! The hot transfer student transferring into our class!\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_05"; }
else { }
}
void ArriveAtSchool_05()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "\"Uuhm , no ?\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_06"; }
else { }
}
void ArriveAtSchool_06()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = "Randel";
textstring = "\"How have you not !!! I bet you're not even interested in girls are you ?! Wait have you finally come out of the closet ?!\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_07"; }
else { }
}
void ArriveAtSchool_07()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "\"Tsk. Cut it out will you ! \"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_08"; }
else { }
}
void ArriveAtSchool_08()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "*Sigh...* He might just be the most anoying person i've ever met";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Bell"; }
else { }
}
void Bell()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = "";
textstring = "*Driiiiiiiiiing*";
}
public void Save()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/TextController Save 1.dat");
SaveData data = new SaveData();
data.text = textstring;
data.playerName = playerName;
data.myState = myState;
bf.Serialize(file, data);
file.Close();
Debug.Log("File Saved.");
}
public void Load()
{
if (File.Exists(Application.persistentDataPath + "/TextController Save 1.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/TextController Save 1.dat", FileMode.Open);
SaveData data = (SaveData)bf.Deserialize(file);
myState = data.myState;
playerName = data.playerName;
textstring = data.text;
file.Close();
Debug.Log("Texcontrollerfiles Loaded");
}
else { Debug.Log("Save file not found."); }
}
}
[System.Serializable]
public class SaveData
{
public string text;
public string playerName;
public string myState;
}
Script that is attatched to the loaded object and the dontdestroyonload object in Scene2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine.SceneManagement;
public class TextController : MonoBehaviour
{
public Text text;
public Text nameText;
public List<string> States;
public string myState;
public BackgroundController backgroundScript;
public string playerName;
public string textstring;
public int background;
public string currentSceneName;
public GameObject NameDataHolder;
public NameSelectTest nameSelectScript;
public LoadAll LoadAllScript;
public SaveAll SaveAllScript;
// Use this for initialization
void Start()
{
myState = "Wakeup";
backgroundScript = GameObject.Find("GameBackground").GetComponent<BackgroundController>();
nameSelectScript = GameObject.Find("NameDataHolder").GetComponent<NameSelectTest>();
LoadAllScript = GameObject.Find("Dataholder").GetComponent<LoadAll>();
SaveAllScript = GameObject.Find("Dataholder").GetComponent<SaveAll>();
playerName = nameSelectScript.playerNameInherit;
Debug.Log("bool: " + LoadAllScript.MainScreenLoadBool);
if (LoadAllScript.MainScreenLoadBool == true)
{
LoadAllScript.LoadAllFunction();
}
}
// Update is called once per frame
void Update()
{
text.text = textstring;
print(myState);
if (myState == "Wakeup")
{
WakyWaky_01();
}
else if (myState == "Wakeup_02")
{
WakyWaky_02();
}
else if (myState == "Wakeup_03")
{
WakyWaky_03();
}
else if (myState == "Waytoschool_01")
{
WayToSchool_01();
}
else if (myState == "Hit_01")
{
Hit_01();
}
else if (myState == "Hit_02")
{
Hit_02();
}
else if (myState == "Hit_03")
{
Hit_03();
}
else if (myState == "Hit_04")
{
Hit_04();
}
else if (myState == "Waytoschool_02")
{
WayToSchool_02();
}
else if (myState == "Waytoschool_03")
{
WayToSchool_03();
}
else if (myState == "Arriveatschool_01")
{
ArriveAtSchool_01();
}
else if (myState == "Arriveatschool_02")
{
ArriveAtSchool_02();
}
else if (myState == "Arriveatschool_02_1")
{
ArriveAtSchool_02_1();
}
else if (myState == "Arriveatschool_03")
{
ArriveAtSchool_03();
}
else if (myState == "Arriveatschool_04")
{
ArriveAtSchool_04();
}
else if (myState == "Arriveatschool_05")
{
ArriveAtSchool_05();
}
else if (myState == "Arriveatschool_06")
{
ArriveAtSchool_06();
}
else if (myState == "Arriveatschool_07")
{
ArriveAtSchool_07();
}
else if (myState == "Arriveatschool_08")
{
ArriveAtSchool_08();
}
else if (myState == "Bell")
{
Bell();
}
}
void WakyWaky_01()
{
backgroundScript.ChangeToRoom();
nameText.text = playerName.ToString();
textstring = "*Yawn* \"Another morning, another day. Well! Time to get up!\" " +
"as i struggle out of my bed to go brush my teeth i hit my toe, *lets out a frustrated grunt*\n\n ";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Wakeup_02"; }
else { }
}
void WakyWaky_02()
{
backgroundScript.ChangeToRoom();
nameText.text = playerName;
textstring = "\"Nope fuck this!\" i get into my bed again and rest some more. \n\n";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Wakeup_03"; }
else { }
}
void WakyWaky_03()
{
backgroundScript.ChangeToRoom();
nameText.text = playerName;
textstring = "My alarm goes off again. I look at the clock: 5 more minutes till school. " +
"\"OH CRAP I GOTTA HURRY!!\" I quickly put on my clothes and leave the house.";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Waytoschool_01"; }
else { }
}
public void WayToSchool_01()
{
nameText.text = playerName;
backgroundScript.ChangeToStreetIMG();
textstring = "\"I hope i can make it in time for the attendence check!\"" +
"\n\n *insert screen shake here*";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Hit_01"; }
else { }
}
void Hit_01()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "\"Auw...\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Hit_02"; }
else { }
}
void Hit_02()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = "?????";
textstring = "\"Hey ! W-w-watch where you're going !\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Hit_03"; }
else { }
}
void Hit_03()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "\"S-Sorry!\" ";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Hit_04"; }
else { }
}
void Hit_04()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "I quickly get back up and continue running to school.";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Waytoschool_02"; }
else { }
}
void WayToSchool_02()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "I kinda feel sorry for her ... , it doesn't look like she's not around here either...\n" +
"Makes me wonder...";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Waytoschool_03"; }
else { }
}
void WayToSchool_03()
{
backgroundScript.ChangeToStreetIMG();
nameText.text = playerName;
textstring = "Well... whatever. I'm sure it's not a big deal.";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_01"; }
else { }
}
void ArriveAtSchool_01()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "I finally arrive at school, looks like i actually made it fairly in time.";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_02"; }
else { }
}
void ArriveAtSchool_02()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = "?????";
textstring = "\"Ooooyy~ !!!\" \" " + playerName + "~ !!!\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_02_1"; }
else { }
}
void ArriveAtSchool_02_1()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "\"Huh ?\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_03"; }
else { }
}
void ArriveAtSchool_03()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "Ah... there he is, Randel , my personal stalker, he who sees me as a valuable friend while i have never even done anything for him...";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_04"; }
else { }
}
void ArriveAtSchool_04()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = "Randel";
textstring = "\"You've heard the rumors haven't you ! The hot transfer student transferring into our class!\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_05"; }
else { }
}
void ArriveAtSchool_05()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "\"Uuhm , no ?\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_06"; }
else { }
}
void ArriveAtSchool_06()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = "Randel";
textstring = "\"How have you not !!! I bet you're not even interested in girls are you ?! Wait have you finally come out of the closet ?!\"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_07"; }
else { }
}
void ArriveAtSchool_07()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "\"Tsk. Cut it out will you ! \"";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Arriveatschool_08"; }
else { }
}
void ArriveAtSchool_08()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = playerName;
textstring = "*Sigh...* He might just be the most anoying person i've ever met";
if (Input.GetKeyDown(KeyCode.Space)) { myState = "Bell"; }
else { }
}
void Bell()
{
backgroundScript.ChangeToSchoolEntranceIMG();
nameText.text = "";
textstring = "*Driiiiiiiiiing*";
}
public void Save()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/TextController Save 1.dat");
SaveData data = new SaveData();
data.text = textstring;
data.playerName = playerName;
data.myState = myState;
bf.Serialize(file, data);
file.Close();
Debug.Log("File Saved.");
}
public void Load()
{
if (File.Exists(Application.persistentDataPath + "/TextController Save 1.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/TextController Save 1.dat", FileMode.Open);
SaveData data = (SaveData)bf.Deserialize(file);
myState = data.myState;
playerName = data.playerName;
textstring = data.text;
file.Close();
Debug.Log("Texcontrollerfiles Loaded");
}
else { Debug.Log("Save file not found."); }
}
}
[System.Serializable]
public class SaveData
{
public string text;
public string playerName;
public string myState;
}
//{
// Wakeup, Wakeup_02, Wakeup_03, Waytoschool_01, Waytoschool_02, Waytoschool_03, Hit_01, Hit_02, Hit_03, Hit_04, Arriveatschool_01, Arriveatschool_02,
// , Arriveatschool_03, Arriveatschool_04, Arriveatschool_05, Arriveatschool_06, Arriveatschool_07, Arriveatschool_08,Bell
//});
bump , i begg of you , ive been stuck several days here :/
Just a quick question, When the error occurs, is NameDataHolder in the root of your hierarchy or a child of another object?
Just dug through your code. I'll be honest, I would expect it to work, as it is, as long as NameDataHolder is in the root in the scene and active, when the start routine runs on TextController and that it contains a script called NameSelectTest.
That being said though, I have a suggestion for you. Read up on singletons. Consider using a singleton in your initial startup scene, and let the singleton hold any/all data that you need to persist through scene changes. It would result in a lot cleaner code, in my opinion, and be a lot easier to work with.
Answer by ruben10 · Dec 26, 2017 at 11:16 PM
I have found what is wrong !
instead of :
myState = "Wakeup";
backgroundScript = GameObject.Find("GameBackground").GetComponent<BackgroundController>();
nameSelectScript = GameObject.Find("NameDataHolder").GetComponent<NameSelectTest>();
LoadAllScript = GameObject.Find("Dataholder").GetComponent<LoadAll>();
SaveAllScript = GameObject.Find("Dataholder").GetComponent<SaveAll>();
playerName = nameSelectScript.playerNameInherit;
Debug.Log("bool: " + LoadAllScript.MainScreenLoadBool);
if (LoadAllScript.MainScreenLoadBool == true)
{
LoadAllScript.LoadAllFunction();
}
it was :
void Start()
{
myState = "Wakeup";
backgroundScript = GameObject.Find("GameBackground").GetComponent<BackgroundController>();
LoadAllScript = GameObject.Find("Dataholder").GetComponent<LoadAll>();
SaveAllScript = GameObject.Find("Dataholder").GetComponent<SaveAll>();
loadGameObject = GameObject.Find("Scriptholder").GetComponent<LoadGameObject>();
Debug.Log("bool: " + LoadAllScript.MainScreenLoadBool);
if (LoadAllScript.MainScreenLoadBool == true)
{
loadGameObject.LoadObject();
if (GameObject.Find("NameDataHolder") == true)
{
LoadAllScript.LoadAllFunction();
}
}
nameSelectScript = GameObject.Find("NameDataHolder").GetComponent<NameSelectTest>();
playerName = nameSelectScript.playerNameInherit;
}
so basically the order of finding the object was wrong , it was searching for the object before it was loaded :)
Solved ! :)