- Home /
Editor Selection and getting a different currentActiveGameObject.
Hey everyone. Sorry about the vague question title, but I didn't know how to word it.
So basically, I'm creating a custom, node-based navigation system with a series of gameObjects with a Node script. There's a custom editor layout button on the script that, when clicked, creates a new node, adds it to a list for the previous node (for gizmo-based path displays), then sets the Selection.activeGameObject to the newly created node.
That all works fine, but what I'm trying to do now doesn't seem to work:
public override void OnInspectorGUI(){
DrawDefaultInspector ();
//This deals with adding new nodes, and works perfectly fine.
Node myTarget = (Node)target;
GameObject curr = Selection.activeGameObject;
if(GUILayout.Button("Extra Node")){
GameObject next = myTarget.CreateNode();
Selection.activeGameObject = next;
}
//This doesn't work.
if(myTarget.connect && curr != myTarget.gameObject){
if(curr.GetComponent<Node>()){
myTarget.AddNode(curr);
Selection.activeGameObject = myTarget.gameObject;
}
else{
Selection.activeGameObject = myTarget.gameObject;
}
}
}
The code above is from my custom inspector for the Node script. The first part works fine, but the second doesn't. Essentially what I'm trying to do is, while the 'connect' bool is true on the selected node, if another node is selected, it gets added to the List (which happens in the AddNode() method), then the selection focuses back on the original node. Does anyone know why this isn't working, or any alternatives?