0

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

  • Can you show what the child looks like? AFAIK a ScriptableObject cannot be a child of a GameObject. – shingo May 29 '23 at 09:45
  • The children look disabled. Findinchildren doesnt work on disabled objects I thought – BugFinder May 29 '23 at 12:26
  • The nameText and descriptionText are disabled, but the scriptable object is part of NoteImage1 which stays active. The OnDrop is part of NoteSlot3, the parent. – Bellatorpoeta May 29 '23 at 15:56

0 Answers0