Quest Machine MiniMap Integration

Announcements, support questions, and discussion for Quest Machine.
Post Reply
DQHomicide
Posts: 7
Joined: Fri Jan 01, 2021 12:53 pm

Quest Machine MiniMap Integration

Post by DQHomicide »

Hi all. new guy here, and a little lost with this Mammoth tool (thats a good thing) :P

Actually, pretty cool stuff, but , i am at a point now where i wish to have icons on my mini map for quest givers, or direction to quests themselves.

I honestly have no idea where to begin. i did do a search here in the forums, but the only info i found was related to QuestDialog. Is this the same?

If there is anyone who could point me to an article, video or anything that touches on this, i would be very greatful. Ty.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Machine MiniMap Integration

Post by Tony Li »

Hi,

Here are two ways to manage minimap icons:

1. Assuming your existing minimap system has a way to turn icons on and off, your quests can use a Scene Event action or custom quest action to turn them on and off.

2. Or you can hook into the existing quest indicator system.

For #1:
  • For discussion, let's say your minimap system has a script named MinimapEntity that controls whether the GameObject's minimap icon is visible or invisible.
  • To use a Scene Event action, find the point in the quest where you want to change the minimap icon, such as the main quest's Active state > Actions, which run when the quest goes active:
    minimapMainActiveActions.png
    minimapMainActiveActions.png (34.37 KiB) Viewed 1226 times
    Add a "Scene Event" action. This is a UnityEvent that's tied to GameObject(s) in a specific scene. You could configure it, for example, to call the MinimapEntity's method to change the icon's visibility:
    minimapSceneEvent.png
    minimapSceneEvent.png (32.05 KiB) Viewed 1226 times
  • If you don't know ahead of time which scene the GameObject will be in, or if you don't want to use a Scene Event, you can write your own custom actions. Make a copy of Plugins / Pixel Crushers / Quest Machine / Templates / QuestActionTemplate.cs. Move it outside the Plugins folder so it can access your minimap system. Then customize it where the comments indicate. For example, your script might look like:

    Code: Select all

    namespace PixelCrushers.QuestMachine
    {
        public class MinimapIconQuestAction : QuestAction
        {
            // These values will appear in the quest editor's inspector:
            public string gameObjectName;
            public bool on;
    
            public override void Execute()
            {
                // Find the GameObject even if it's inactive:
                var gameObject = GameObjectUtility.GameObjectHardFind(gameObjectName);
    
                // Set its minimap icon on or off:
                gameObject.GetComponent<MinimapEntity>().SetMinimapIcon(on);
            }
        }
    }
    Then add that action:
    minimapCustomAction.png
    minimapCustomAction.png (23.99 KiB) Viewed 1226 times
For #2:
  • Quest Machine has 5 built-in types of UIs:
    • Quest Dialogue UI: Used by quest givers to show offer text, quest hand-ins, etc.
    • Quest Journal UI: Window showing the details of the player's active and completed quests.
    • Quest HUD: Onscreen summary of active quests.
    • Quest Alert UI: Informational messages that pop up onscreen for a duration, such as "Task completed. Return to NPC."
    • Quest Indicators: Typically shown as overhead images to indicate that a quest giver wants to talk.
    You can use quest indicators for other things, such as showing an overhead image on kill quest targets.
  • When a GameObject (e.g., quest giver) has a quest indicator, it's managed by a QuestIndicatorManager script that figures out what indicator image to show. The QuestIndicatorManager manages another script called QuestIndicatorUI that actually shows the indicator image. Look at any of the NPCs, such as the Villager, in the Demo scene, to see how it's set up. Both of these scripts are subclassable. You can make a subclass of QuestIndicatorUI that also sets your minimap icon. For example, the subclass might look like:

    Code: Select all

    public class CustomQuestIndicatorUI : QuestIndicatorUI
    {
        public override void SetIndicator(int index, bool value)
        {
            base.SetIndicator(index, value);
            
            // If requested to set the "Interact" indicator, also set the minimap icon:
            if (index == (int)QuestIndicatorState.Interact)
            {
                GetComponentInParent<MinimapEntity>().SetMinimapIcon(value);
            }
        }
    }
  • A GameObject's QuestIndicatorManager typically points to a prefab that has a QuestIndicatorUI script. At runtime, it instantiates the prefab. (It's also fine if the QuestIndicatorManager points to a scene object instead of a prefab.) Replace the prefab/scene object's QuestIndicatorUI with your custom subclass.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Machine MiniMap Integration

Post by Tony Li »

The second part of this is making sure that minimap icons are turned back on/off when the player leaves the scene and returns; or saves the game, quits, and loads the saved game.

The easiest way to do this is to save the minimap icon's state. Quest Machine's save system is fairly easily extended. To save data, write a small "Saver" script. You can find a starter template in Plugins / Pixel Crushers / Common / Templates. Example:

Code: Select all

namespace PixelCrushers
{
    public class MinimapEntitySaver : Saver
    {
        public override string RecordData()
        { // Return "Y" if the icon is on:
            return GetComponent<MinimapEntity>().isOn ? "Y" : "N";
        }
        public override void ApplyData(string data)
        { // Set the icon state based on the saved data:
            GetComponent<MinimapEntity>().SetMinimapIcon(data == "Y");
        }
    }
}
DQHomicide
Posts: 7
Joined: Fri Jan 01, 2021 12:53 pm

Re: Quest Machine MiniMap Integration

Post by DQHomicide »

Well, my entire game is in a single scene at all times, so that part is easy enough to not worry about. But im still stumblin around trying to figure out the first steps mentioned. I'm a real knuclehead of sorts, i never import demo scenes, and i note that you specifaclly mentioned it as reference. I think i may break my rule of thumb this once. Thanks Tony.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Machine MiniMap Integration

Post by Tony Li »

You could import the demo scene into a separate project just to see how it works. No need to keep it in your main project if you don't want to.

Since I don't know how your minimap system is designed, I tried to supply a few different options. A basic Scene Event action is probably the easiest way to go.
DQHomicide
Posts: 7
Joined: Fri Jan 01, 2021 12:53 pm

Re: Quest Machine MiniMap Integration

Post by DQHomicide »

Indeed. Well, for now, i have taken your advice on the demo scene and am getting aquainted with things. Shall see how it goes. :D
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Machine MiniMap Integration

Post by Tony Li »

BTW, there's also a whole series of video tutorials that may be helpful:
https://www.pixelcrushers.com/quest-mac ... tutorials/
DQHomicide
Posts: 7
Joined: Fri Jan 01, 2021 12:53 pm

Re: Quest Machine MiniMap Integration

Post by DQHomicide »

Yea, this stuff is awsome, and its starting to click. Thanks for the links, the help, and the plugin :D. Amazing stuff.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Machine MiniMap Integration

Post by Tony Li »

Glad to help!
Post Reply