Can't Find Children After Drag and Drop to New Parent in Unity

79 Views Asked by At

I am able to move a transform with scriptable object "note" to a new parent "note slot" and have it appear as a child in the editor, but I can't find it using code. It says there are no children.

After dropping the note using IDropHandler, I try to find the new child and the scriptable object in it, but it's not there according to Visual Studio.

private NoteScriptableObject referenceNote;

public void OnDrop(PointerEventData eventData)
    {
        if (eventData.pointerDrag != null && transform.childCount == 0)
        {
            DDScriptableTest note = eventData.pointerDrag.GetComponent<DDScriptableTest>();
            note.parentAfterDrag = transform;
            SetNote(GetComponentInChildren<DDScriptableTest>().GetNote());
        }
        Debug.Log(transform.childCount);//zero        
        Debug.Log(referenceNote);//null
    }

public void SetNote(NoteScriptableObject note)
    {
        referenceNote = note;
    }

I tried using an event instead but that didn't work either.

    private void Start()
    {
        NewNote += UI_CharacterNoteSlot_NewNote;
    }

    private void UI_CharacterNoteSlot_NewNote(object sender, EventArgs e)
    {
        Debug.Log(transform.childCount);
    }

NewNote?.Invoke(this, EventArgs.Empty);//Inside OnDrop

I know there is a child because the editor shows it, so why can't I access it?

Editor Editor view of child

0

There are 0 best solutions below