- Home /
This question was
closed Apr 08 at 09:43 PM by
PresidentTree for the following reason:
The question is answered, right answer was accepted
Question by
PresidentTree · Apr 06 at 11:58 PM ·
scripting problemprefabsscript error
Prefab clones aren't deleting?
I have prefabs for a chat log that should be deleted once the dialogue box closes. Although they are removed from the chat log, they are not actually deleted and take up space within the chat log when the dialogue box opens. I do not know what I am doing wrong. Any help is appreciated. Here is my code:
//Toggle dialogue box:
void ToggleDialogueBox()
{
if (!dialogueBox.gameObject.activeSelf && Input.GetKeyDown(KeyCode.T))
{
dialogueBox.gameObject.SetActive(true);
textIndex = 0;
choiceNum = 0;
skipping = false;
dialogueScript.Clear();
prefabList.Clear();
}
else if (dialogueScript.Count == textIndex)
{
StopAllCoroutines();
foreach (TextMeshProUGUI item in prefabList)
{
Destroy(item);
}
dialogueBox.gameObject.SetActive(false);
}
}
//Makes a list of prefabs:
void WriteToLog(string name, string text)
{
if (name == null)
{
prefab.text = text;
}
else
{
prefab.text = name + ": " + text;
}
TextMeshProUGUI clone = Instantiate(prefab, content);
prefabList.Add(clone);
}
Comment
Best Answer
Answer by Hawaii_Dev · Apr 07 at 10:08 AM
You are only deleting the textmeshprougui component on the object. Change the "Destroy(item)" to Destroy(item.gameObject)" to destroy the whole gameobject and not only the component. @PresidentTree