Question by
epicgooner1 · Nov 13, 2018 at 06:13 AM ·
c#2drpg-game
Script is nested inside a canvas but I am still getting a "The Object of type __ has been destroyed but you are still trying to access it"
I am an absolute beginner to unity and I have been following a 2D RPG tutorial online, I have a quest manager that links to different quest objects but when I load a new scene I get the error "Object of type __ has been destroyed but you are still trying to access it." the quest objects are childs of the canvas which is not destroyed on load and the empty game objects they are attached to are also not destroyed on load. I have looked at other forums but I don't fully understand the responses, if anyone could help me it would be much appreciated. Here is the full script of the quest object.
public int questNumber;
public QuestManager theQM;
public string startText;
public string endText;
public bool isItemQuest;
public string targetItem;
public bool isEnemyQuest;
public string targetEnemy;
public int enemiesToKill;
private int enemyKillCount;
// Use this for initialization
void Start () {
theQM = FindObjectOfType<QuestManager>();
}
// Update is called once per frame
void Update () {
if (isItemQuest)
{
if (theQM.itemCollected == targetItem)
{
theQM.itemCollected = null;
EndQuest();
}
}
if (isEnemyQuest)
{
if (theQM.enemyKilled == targetEnemy)
{
theQM.enemyKilled = null;
enemyKillCount++;
}
if (enemyKillCount >= enemiesToKill)
{
EndQuest();
}
}
}
public void StartQuest()
{
theQM.ShowQuestText(startText);
}
public void EndQuest()
{
theQM.ShowQuestText(endText);
theQM.questCompleted[questNumber] = true;
gameObject.SetActive(false);
}
} [/code]
Comment