Detach children is effecting the player and his model

After implementing the detach children line in the QuestListUI script, when I press Play the character runs in place and the camera follows the invisible player. its fixed when I comment out the line with detach children but then the quest system won’t work,

What did I do wrong and how can I fix it?

I just fount the bug fix and more Predicates where it changed detach children into a foreach loop but now the player model is just gone. I don’t think the QuestListUI should be able to do that to the player model but I don’t get where I went wrong.

It definitely shouldn’t. It should be deleting the children of the container, not anything on the player.
Check to make sure that you’ve linked the correct object for the container.
Paste in your QuestListUI.cs script of everything looks right in the inspector.

using System.Collections;
using System.Collections.Generic;
using RPG.Quests;
using UnityEngine;

public class QuestListUI : MonoBehaviour
{
    [SerializeField] QuestItemUI questPrefab;
    QuestList questList;

    // Start is called before the first frame update
    void Start()
    {
        questList = GameObject.FindGameObjectWithTag("Player").GetComponent<QuestList>();
        questList.onUpdate += Redraw;
        Redraw();
    }

    private void Redraw()
    {
        foreach (Transform item in transform)
        {
            Destroy(item.gameObject);
        }
        foreach (QuestStatus status in questList.GetStatuses())
        {
            QuestItemUI uiInstance = Instantiate<QuestItemUI>(questPrefab, transform);
            uiInstance.Setup(status);
        }
    }
}

The QuestListUI script should be on the UI container, not on the player. With it on the player, as soon as the script runs, it will delete everything on the player like the root and model…

1 Like

Privacy & Terms