Forum rules - please read before posting.

Using AC objectives

edited October 2020 in Technical Q&A

Hello
We need to add objectives to our game. We saw such thing in AC but it's not clear how to tune them to our needs.
We don't need all goals to be seen at start but to add them at certain points of a gameplay. Also, we need that finished tasks could be marked.
Now AC allows to show all objectives at once or certain type of them.
What could you advice in this situation?

Here is the example. Tasks here add during gameplay.
https://media.discordapp.net/attachments/514801471494160394/765208728928256000/unknown.png

Comments

  • Setting an InventoryBox element's Objectives to display to All will show all Objectives that are active, completed, or failed. Those that haven't been started will not be shown.

    You can begin an objective by using the Objective: Set state Action to mark it as Started. Only then will it be possible to display it in a Menu.

    For the example above, set it to All. This will list active and completed objectives.

    To then also display either a tick or question-mark icon, depending on its state, you just need a simple script to check the objective state.

    Make a Unity UI-based Menu to list your Objectives, and then attach a separate set of Image components in your UI's hierarchy - to show the desired icon.

    Then attach this script to each:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class ObjectiveIcon : MonoBehaviour
    {
    
        public int slot;
        public Sprite completed;
        public Sprite notCompleted;
        public Image image;
    
        void OnEnable ()
        {
            ObjectiveInstance[] objectives = KickStarter.runtimeObjectives.GetObjectives ();
            if (slot >= 0 && slot < objectives.Length)
            {
                if (objectives[slot].CurrentState.stateType == ObjectiveStateType.Complete)
                {
                    image.sprite = completed;
                }
                else
                {
                    image.sprite = notCompleted;
                }
            }
        }
    
    }
    

    Fill in the Inspector fields, setting the Slot value to 0 for the first-shown, 1 for the second, etc. When the Objectives are shown, the icon should then be set correctly depending on its completed state.

  • edited March 2023

    _ For the example above, set it to All. This will list active and completed objectives.

    To then also display either a tick or question-mark icon, depending on its state, you just need a simple script to check the objective state.

    Make a Unity UI-based Menu to list your Objectives, and then attach a separate set of Image components in your UI's hierarchy - to show the desired icon.

    Then attach this script to each:_

    ´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´

    I don't understand, the menu to create is an AC menu so instead of using adventure creator is to use ui - unity?

    I was using the AC objectives menu. I would like to customize with icons and I didn't understand where to use this script and what type of menu to create.

  • The script above relies on a Unity UI-based Objectives menu.

    Each of the default menus work with Unity UI - set the Menu's Source property to Unity Ui Prefab to use its Unity UI counterpart. Updating the Menu's appearance is then a case of modifying the linked Canvas prefab, ObjectivesUI.

    In what way specifically are you looking to customise the Menu?

  • In what way specifically are you looking to customise the Menu?

    similar to the one in the topic
    https://media.discordapp.net/attachments/514801471494160394/765208728928256000/unknown.png

  • You'll need to start with an Objectives UI canvas that displays a list of active and completed Objectives, and then add Images to the left of each in the Hierarchy. Give them the green "tick" sprite and line up things so that the layout is correct.

    Then, attach the script to each Image, assigning the Image component in its Inspectors, the completed / not completed sprites, as well as its slot index (first = 0, second = 1, etc). When the Menu then turns on, the Images should be updated accordingly.

  • It worked. thanks.

  • Hi Chris,

    I'm having an issue with this script. I don't know why but the sprite representing the status doesn't update when I use the up/down buttons. When I move the objectives up or down, the right status sprite doesn't "follow" the objective in the grid. It stays, so then you can have another goal below marked as completed when has just started.

  • It's an old script, which doesn't account for the Objective list element's offset value - or the filtering options you may have set in the element.

    Try this:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class ObjectiveIcon : MonoBehaviour
    {
    
        public int slot;
        public Sprite completed;
        public Sprite notCompleted;
        public Image image;
        public string menuName, elementName;
    
        void OnEnable ()
        {
            var element = PlayerMenus.GetElementWithName (menuName, elementName);
            if (element == null) return;
    
            int offset = element.GetOffset ();
            var inventoryBox = element as MenuInventoryBox;
    
            var objective = inventoryBox.GetObjective (slot + offset);
            if (objective != null)
            {
                image.enabled = true;
                if (objective.CurrentState.stateType == ObjectiveStateType.Complete)
                {
                    image.sprite = completed;
                }
                else
                {
                    image.sprite = notCompleted;
                }
            }
            else
            {
                image.enabled = false;
            }
        }
    
    }
    
  • edited March 21

    Hi Chris,

    Unfortantely still doesn't work. The first time I open the objectives menu I can see the icons, but again, when I scroll up or down it doesn't update the position of the started/completed icon. It doesn't update the icon either when there is a status update.
    Also weird things start to happen when I close and reopen the Objectives menu: missing icons.

    This is my setup:


  • My mistake - try renaming the script's OnEnable function to Update.

  • Unfortunately the icon doesn't properly update to match the task position. Additionally, there's an unusual issue where the icon fails to appear for tasks with ID4 and above.

  • What's the exact behaviour you get, what's your AC version, and what are the properties of the ObjectivesList element?

  • edited March 24

    Here is the time sequence in the screenshots. Let me know if it's still not clear.

    I'm in version 1.81.4

    FYI: I didn't create any extra element in the Objective Menu for the icon. I only rely on your script.

    https://imgur.com/a/KFJGMD6

  • Apologies again, the passing of the offset index is not necessary as this is accounted for already.

    This should do it:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class ObjectiveIcon : MonoBehaviour
    {
    
        public int slot;
        public Sprite completed;
        public Sprite notCompleted;
        public Image image;
        public string menuName, elementName;
    
        void Update ()
        {
            var element = PlayerMenus.GetElementWithName (menuName, elementName);
            if (element == null) return;
    
            var inventoryBox = element as MenuInventoryBox;
            var objective = inventoryBox.GetObjective (slot);
    
            if (objective != null)
            {
                image.enabled = true;
                if (objective.CurrentState.stateType == ObjectiveStateType.Complete)
                {
                    image.sprite = completed;
                }
                else
                {
                    image.sprite = notCompleted;
                }
            }
            else
            {
                image.enabled = false;
            }
        }
    
    }
    
  • Yes! That works! Thanks a lot!

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.