Forum rules - please read before posting.

Objectives: "Select After" option

2»

Comments

  • Could not find Menu for Canvas ObjectivesUI(Clone) (UnityEngine.Canvas)
    UnityEngine.Debug:LogWarning (object,UnityEngine.Object)
    ForceSelectObjective:OnEnable () (at Assets/Detective_AC/Scripts/ForceSelectObjective.cs:13)
    UnityEngine.Object:Instantiate<UnityEngine.Canvas> (UnityEngine.Canvas)
    AC.Menu:LocateLocalCanvas () (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:3289)
    AC.Menu:LoadUnityUI (bool) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:400)
    AC.Menu:TurnOn (bool) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:1979)
    AC.PlayerMenus:CheckCrossfade (AC.Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2238)
    AC.Menu:EndTransitionOff () (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:1830)
    AC.Menu:HandleTransition () (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:2291)
    AC.PlayerMenus:UpdateMenu (AC.Menu,int,bool,bool) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1039)
    AC.PlayerMenus:UpdateAllMenus () (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2138)
    AC.StateHandler:Update () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:245)
    

    I checked my ObjectivesUI prefab and I can see the Canvas component, but the Grid component, where the buttons are placed, only has the RectTransform.

    https://imgur.com/a/pNr3ruu

  • Odd, should work in that case.

    The other approach is to just reference the Menu by name:

    using UnityEngine;
    using AC;
    
    public class ForceSelectObjective : MonoBehaviour
    {
    
        void OnEnable()
        {
            if (KickStarter.runtimeObjectives == null || KickStarter.runtimeObjectives.SelectedObjective == null) return;
    
            var menu = PlayerMenus.GetMenuWithName("Objectives");
            var inventoryBox = menu.GetElementWithGameObject(gameObject) as MenuInventoryBox;
    
            var slot = inventoryBox.GetSlotIndex(gameObject);
            if (inventoryBox.GetObjective(slot) == KickStarter.runtimeObjectives.SelectedObjective)
            {
                KickStarter.playerMenus.SelectUIElement(gameObject);
            }
        }
    
    }
    
  • I'm afraid still doesn't work.
    I have this error for each of the three buttons I have with the script attached.

    I share some more screenshots of the setup:
    https://imgur.com/a/ulJureF

    NullReferenceException: Object reference not set to an instance of an object
    ForceSelectObjective.OnEnable () (at Assets/Detective_AC/Scripts/ForceSelectObjective.cs:14)
    UnityEngine.Object:Instantiate(Canvas)
    AC.Menu:LocateLocalCanvas() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:3289)
    AC.Menu:LoadUnityUI(Boolean) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:400)
    AC.Menu:TurnOn(Boolean) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:1979)
    AC.PlayerMenus:CheckCrossfade(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2238)
    AC.Menu:EndTransitionOff() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:1830)
    AC.Menu:HandleTransition() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:2291)
    AC.PlayerMenus:UpdateMenu(Menu, Int32, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1039)
    AC.PlayerMenus:UpdateAllMenus() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2138)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:245)
    
  • Thank you for your continued patience.

    Let's try this:

    using UnityEngine;
    using AC;
    
    public class ForceSelectObjective : MonoBehaviour
    {
    
        void OnEnable()
        {
            if (KickStarter.runtimeObjectives == null || KickStarter.runtimeObjectives.SelectedObjective == null) return;
    
            var menu = PlayerMenus.GetMenuWithName("Objectives");
            var inventoryBox = menu.GetElementWithName("ObjectivesList") as MenuInventoryBox;
    
            var slot = inventoryBox.GetSlotIndex(gameObject);
            if (inventoryBox.GetObjective(slot) == KickStarter.runtimeObjectives.SelectedObjective)
            {
                KickStarter.playerMenus.SelectUIElement(gameObject);
            }
        }
    
    }
    
  • edited September 17

    Okay, so it still doesn't work, but at least now I don't have the warnings. :wink:
    In previous iterations, the Description was visible, but now it isn't showing up. So basically, we're back to the initial state - no Objective is selected and the attached description isn't being displayed.

    And don't worry at all. I'm happy you are willing to help me here! :)

  • edited September 18

    The script above wouldn't affect the Description's visibility. You're saying that this last change caused it to go?

    At this point, I would need to see the setup for myself to determine what's going on. If you can PM me your project (sans Library folder) with clear recreation instructions, I will take a look.

  • The project is too big to share. I'll try to recreate the sceneario in some basic project in a few days.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.