Help! How do I change default selected buttons on different SetActive() panels ???

I have a panel for a point and click adventure style game with a constant nav on the bottom of the screen using the 4.6 ui.

i have triange on my ps3 as the button to activate the other panel, another navigation menu for items, keys, docs, options, and save/load… sort of like darksouls i guess. I want my shoulder buttons to nav these buttons.

this would turn on at the top of my screen, and the 1st nav should turn off.

I’ve set the exam button as first selected in the event system. since i can’t add 2 or more event systems in a single scene, when i activate the top nav, there is no selected or selectable button. The 1st panel is explicit left / right/up/down transition and it relates to my joypad dpad. and panel 2 is horizontal which should respond to my L1 and R1 buttons.

A user named Orb helped me get to the point of using SetSelectedGameObject() but I cannot find much documentation on using these new functions… methods?? I’m a UnityScript guy.

The problem is weird:
the items button highlights, and on left or right dpad press it wants to go to the next item but snaps back to items. the R1 and L1 make my print() shows the next button as being selected in console but it snaps right back to the items button.

the menus open and close fine so far. i’m realyl going to need to master this to work in more sub menus. It’s too bad i cant just have more than 1 event system.

Thank you for any help!!!

Here is the code:

#pragma strict
import UnityEngine.EventSystems;

public var main_canvas : GameObject;

public var screen_nav_panel : GameObject;
public var inv_nav_panel : GameObject;
public var diag_box : GameObject;
public var diag_text : GameObject;

private var inventoryon : boolean;
private var diagon : boolean;
private var itemon : boolean;

public var exam_button : GameObject;

public var items_button : GameObject;
public var docs_button : GameObject;
public var keys_button : GameObject;
public var options_button : GameObject;
public var saveload_button : GameObject;


public var event_object : GameObject;
var event_system : UnityEngine.EventSystems.EventSystem;
var exam_button_logic : ExamButton;
var es : EventSystem;

function Start ()
    {
   
        // either this is correct
        event_system = event_object.GetComponent(EventSystems.EventSystem);
        //or this
        es = EventSystemManager.currentSystem;
       
       
        main_canvas = this.gameObject;
        exam_button_logic = exam_button.GetComponent(ExamButton);   

       
       
        screen_nav_panel.SetActive(true);
        inv_nav_panel.SetActive(false);
        diag_box.SetActive(false);
        diag_text.SetActive(false);
       
        inventoryon = false;
        diagon = false;
        itemon = false;
    }

function Update ()
    {
            // refference each nav button.
            // while exam is selected / highlighted
            if(exam_button_logic.exam_selected == true)
            {
                if(Input.GetButtonDown("Submit"))
                    {
                        diagon = true;
                    }
                else
                if(Input.GetButtonDown("Cancel"))
                    {
                        diagon = false;
                    }
            }
            else
            if(exam_button_logic.exam_selected == false)
                {
                    diagon = false;
                }   
           
            //////////////////////////////////////////////////////////////
            // turn on inventory       
            if(Input.GetButtonDown("Inventory"))
                    {
                        inventoryon = true;
                        diagon = false;
                       
                        screen_nav_panel.SetActive(false);
                        inv_nav_panel.SetActive(true);
                    }
           
            //////////////////////////////////////////////////////////////////
            // when inventory is meant to be on
            if(inventoryon == true)
                {   
                    itemon = true;
                    es.SetSelectedGameObject(items_button, null);
                }
            else
            if(inventoryon == false)
                {
                    itemon = false;
                    screen_nav_panel.SetActive(true);
                    inv_nav_panel.SetActive(false);
                }
               
               
                if(itemon == true)
                    {
                            if(Input.GetButtonDown("L1"))
                                {
                                    itemon = false;
                                   
                                    es.SetSelectedGameObject(saveload_button, null);
                                    print(event_system.currentSelectedObject);
                                }
                            else
                            if(Input.GetButtonDown("R1"))
                                {
                                    itemon = false;
                                    es.SetSelectedGameObject(docs_button, null);
                                    print(event_system.currentSelectedObject);
                                }
                            else
                            if(Input.GetButtonDown("Cancel"))
                                {
                                    itemon = false;
                                    es.SetSelectedGameObject(exam_button, null);
                                    inventoryon = false;
                                    print(event_system.currentSelectedObject);
                                }
                        }
               
           
                   
            // when diag is meant to be on
            if(diagon == true)
                {
                    diag_box.SetActive(true);
                    diag_text.SetActive(true);
                   
                    if(Input.GetButtonDown("Cancel"))
                        {
                            diagon = false;
                        }
                }
            else
            if(diagon == false)
                {
                    diag_box.SetActive(false);
                    diag_text.SetActive(false);
                }
           
           
    }

Whew, that’s a lot of code to go through! Forgive me for skimming. =)

So SetSelectedGameObject() indeed sets the correct GO to be selected. You can then trigger the “move” animations using ExecuteEvents, like so:

AxisEventData axisEventData = newAxisEventData(event_system);
axisEventData.moveDir = MoveDirection.Right; //or Left, Up, Down
ExecuteEvents.Execute(event_system.lastSelectedObject, axisEventData, ExecuteEvents.moveHandler);

In this case however, you’re dealing with multiple inputs and menus at the same time. While you might be able to make due with the standard StandaloneInputModule and EventSystem classes, you might want to consider writing your own classes instead, extending from BaseInputModule and EventSystem respectively.

This might seem a bit intimidating, but is actually quite managable in my experience! You can find some (unfinished) documentation on all of the new features in your local copy of the Unity docs.

Hope that helped a bit!

so for javascript:

var axisEventData : AxisEventData;

function start()
{
axisEventData = newAxisEventData(event_system);
}

function update()
{
       if(on button down R1 ( for example )
        {
       axisEventData.moveDir = MoveDirection.Right;
       ExecuteEvents.Execute(event_system.lastSelectedObject, axisEventData, ExecuteEvents.moveHandler);
         }
}

would this be correct?

not working =(
I thought of turning the selected object to null, null to clear the selection before switching but that dosent seem to work.

// when item is selected
            if(es.currentSelectedObject == items_button)
                {
                    if(Input.GetButtonDown("L1"))
                        {
                            itemon = false;
                            keyson = false;
                            docson = false;
                            optionson = false;
                            saveloadon = true;
                          
                            es.SetSelectedGameObject(null, null);
                            es.SetSelectedGameObject(saveload_button, null);
                            print(event_system.currentSelectedObject);
                          
                            axisEventData.moveDir = MoveDirection.Left;
                               ExecuteEvents.Execute(event_system.lastSelectedObject, axisEventData, ExecuteEvents.moveHandler);
                        }
                    else
                    if(Input.GetButtonDown("R1"))
                        {
                            itemon = false;
                            keyson = false;
                            docson = true;
                            optionson = false;
                            saveloadon = false;
                          
                            es.SetSelectedGameObject(null, null);
                            es.SetSelectedGameObject(docs_button, null);
                            print(event_system.currentSelectedObject);

                            axisEventData.moveDir = MoveDirection.Right;
                               ExecuteEvents.Execute(event_system.lastSelectedObject, axisEventData, ExecuteEvents.moveHandler);
                        }
                    else
                    if(Input.GetButtonDown("Cancel"))
                        {
                            inventoryon = false;
                      
                            itemon = false;
                            keyson = false;
                            docson = false;
                            optionson = false;
                            saveloadon = false;
                      
                            es.SetSelectedGameObject(null, null);
                            es.SetSelectedGameObject(exam_button, null);
                          
                            print(event_system.currentSelectedObject);
                        }
                }

it wont deselect the items button =( hellllllllllllllllllllllllllllllllllllllllllllllllllllllllllllp

i have the problem solved.
wow, i had to correct a few nesting issues but this handles that last bit since 90 something people read this and couldn’t answer lol.

                    // alocate the selections via bool flips
                    if(default_selection == true)
                        {
                            es.SetSelectedGameObject(items_button, null);
                               
                            if(item_button_logic.item_selected == true)
                                {
                                    itemon = true;
                                }
                            }
                       
                    // also do it without it having to be defaulted
                    if(inventoryon == true)
                        {
                            if(item_button_logic.item_selected == true)
                                {
                                    itemon = true;
                                }
                        }
                    }