How to drag a specific component reference from one object's Inspector view to another one?
I have a GameObject with two copies of the same component: an "on" Tween and an "off" Tween. I also have a TweenHandler component with two variables: onTween and offTween. If all three components are on the same GameObject, I can open the Inspector view and use my mouse to drag the "on" Tween up to the onTween slot in TweenHandler, and the "off" Tween up to the offTween slot. Everything works perfectly.
But if the TweenHandler component is on a different GameObject, how do I drag the "off" Tween reference over to the offTween slot on the other object? How do I switch the inspector window to the 2nd GameObject?
Assume I can't touch the code. I just want to know if this is possible using drag & drop.
I didn't even know you could drag the component itself, I always dragged the whole object. This will be soooo useful :)
Answer by sarahnorthway · Aug 22, 2016 at 12:06 AM
Ahah! That was fast. I didn't realize you could have multiple inspector windows open.
Right-click the Inspector title and pick "Open Tab". Navigate to object #1 in one Inspector then click the little lock icon at the top-right of the Inspector view. Navigate to object #2 in the other Inspector, and drag the "off" Tween over.
This is also what I am doing. The editor will always pick the 1st component that matches the field type you need from top to bottom, so you can predict which component will be selected when dragging a game object to a component inspector field. However, moving components up and down is tedious so it is hard to exploit to drag one component and then another one.
I wish you had the option to see all components that match the field type when clicking on the small circle on the right of the inspector field. This would show multiple components on the same game object, in the format "GameObject (Component X)" where X is the number of the component if there are multiple components of the same type on the game object. In general, I use multiple components that derive from the same base class, but have different subclasses, so just having "GameObject (Component)" ins$$anonymous$$d of just "GameObject" in the inspector field "circle" selection menu would help me a lot already. Does anybody know a Unity plugin for that?
Your answer
Follow this Question
Related Questions
Preprocessor conditional code for cleaner inspector options 1 Answer
Creating game objects from inspector 0 Answers
How do I bind the value of a public variable from the inspector to some other variable/constant? 0 Answers
public bool not showing in inspector 1 Answer
I have assigned it, but I get an error of Unassigned Reference Exception! 1 Answer