Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Drag component from child of a prefab to scriptable object.

Discussion in 'Editor & General Support' started by koirat, Sep 30, 2023.

  1. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,004
    What I have tried to do, was to drag component attached to child GameObject of particular prefab and drag it to ScriptableObject to create link.
    To my surprise it was not possible since when I enter prefab edit mode to reach the component I cannot drag it to scriptable object field. (It disallows to drag components to objects outside prefab in prefab edit mode).

    Is there a solution to this problem ?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Pretty sure you can only reference the root of prefabs outside of the prefab.

    The solution is to provide a link script at the root of the prefab.

    You would drag a reference to that link script into the ScriptableObject.

    Although I don't think that will get you anything, as that is just the prefab, not whatever live instanced copies of the prefab that you put in the scene.

    You could never drag a link from a scene object into any ScriptableObject asset, obviously.
     
    koirat likes this.
  3. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,004
    Good to know. And I'm a little surprised, I could swear I saw once that someone referenced from inside the prefab. This is why I was trying it.

    Yes I have done something like this, to be more precise proxy component.

    I need it for in Editor functionality, I'm generating some assets.