Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Refering a component into another component of the same object in the inspector

Discussion in 'Editor & General Support' started by Zoro321, Feb 1, 2021.

  1. Zoro321

    Zoro321

    Joined:
    Nov 15, 2013
    Posts:
    13
    Hi,


    Let say i have a script named "Mall=GoToPosition", which inherits a class names "NPCState".




    I add this component to a game object (an animated avatar).

    Now, I have another script named "NPCStateController", which contains an array of "NPCState" typed objects.


    I also add this script to my same object.


    Now, I need to refer the first component (MallGoToPosition) in the array of my second component (NPCStateController).


    How so I do that ?

    See attached picture. surrounded in red is the NPCState array and surrounded in black is the MallGoToPosition component.



    This is not my design. I have been assigned to work on this ptojrct and I do not understand how the folks did that.

    I now it is possiblr since the previous programmer has done that.

    If I try to drag my MallGoToPosition object to an NPCState element of my array, it dpes not work.

    Usualy, we drags objects from the scene graph.


    I really not understand ho to do that and I would need help.


    Thanks alot ! UnityForumsQuestion.png UnityForumsQuestion.png UnityForumsQuestion.png UnityForumsQuestion.png
     
  2. Zoro321

    Zoro321

    Joined:
    Nov 15, 2013
    Posts:
    13
    Sorry for having posted 4 times the same image !
     
  3. Zoro321

    Zoro321

    Joined:
    Nov 15, 2013
    Posts:
    13
    Hi,

    I found the solution !


    I had to set the inspector in Debug mode for the specific game object and after that I was able to drag my MallGoToPosition object onto the NPCState array element.

    Could anyone explain me why I needed to do it ?

    Should I not be able to do it in Normal mode ?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    You can do it in normal mode. You just have to grab the top of the component you want to drag it into the slot.

    Also, don't forget the little lock icon in the upper right of the editor; that's handy for dragging a bunch of things into a list all at once.