Quest HUD text positioning

Announcements, support questions, and discussion for Quest Machine.
Post Reply
rdanielson
Posts: 5
Joined: Thu Feb 17, 2022 1:18 pm

Quest HUD text positioning

Post by rdanielson »

I have a situation where I'd like to display quest text in multiple locations on the HUD, depending on the quest. For instance, I would like to display part of a quest message to the left of the screen and the other part on the right of the screen (surrounding the player); both of these messages would be attached to the same quest node as HUD body text. Ideally, I'd be able to choose where I want the HUD text to end up from within the quest node. Is there a way to obtain this sort of granular positioning within quest machine? I'm pretty new to the UI stuff in Unity and am having trouble coming up with a solution for this. Thank you for any suggestions!
User avatar
Tony Li
Posts: 21928
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest HUD text positioning

Post by Tony Li »

Hi,

Quest Machine lets you define your own UI content types, such as left-side text versus right-side text. While you could tackle text positioning some other way, I recommend creating a new content type if you're a little comfortable with scripting. To do so:

1. Use the regular body text content type for right-side text.

2. Duplicate QuestContentTemplate.cs (located in the Templates folder). Name it something like LeftSideTextQuestContent, and make it a subclass of BodyTextQuestContent. It doesn't need any extra code:

Code: Select all

public class LeftSideTextQuestContent : BodyTextQuestContent {}
3. Quest Machine will automatically recognize your new content type and show it in dropdown menus. Use it for left-side text.

4. Make a subclass of UnityUIQuestHUD. Use this subclass on your HUD instead of the original UnityUIQuestHUD class. Override the AddBodyContent() method to add support for your new LeftSideTextQuestContent:

Code: Select all

public class MyQuestHUD : UnityUIQuestHUD
{
    leftSideBodyTemplate; // <--ASSIGN IN INSPECTOR
    
    protected virtual void AddBodyContent(BodyTextQuestContent bodyContent)
    {
        if (bodyContent is LeftSideTextQuestContent)
        {
            var instance = Instantiate<UnityUITextTemplate>(leftSideBodyTemplate);
            currentContentManager.Add(instance, currentContentContainer);
            instance.Assign(bodyContent.runtimeText);
            currentIconList = null;
        }
        else        
        {
            base.AddBodyContent(bodyContent);
        }
    }
}
rdanielson
Posts: 5
Joined: Thu Feb 17, 2022 1:18 pm

Re: Quest HUD text positioning

Post by rdanielson »

Hi Tony,

Thanks for the swift response, I never noticed the templates. I've followed your instructions but something is not working. QuestMachine is recognizing the LeftSideTextQuestContent and I'm able to select it for text. I've attached the custom MyQuestHUD to a new Quest HUD positioned on the left side of the screen, however the text that's supposed to end up there is showing up on the right side. You mention that I should override AddBodyContent; where should I be doing this? Thanks again for your time!
User avatar
Tony Li
Posts: 21928
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest HUD text positioning

Post by Tony Li »

Make sure you're using your new quest HUD. Assign it to the Quest Machine GameObject's Default Quest HUD or to the player's Quest Journal > UI Settings.

You should only have one quest HUD. It should support left text and right text. Create a different UI template for the left side body text. For example, duplicate Active Body Text Template, rename it Left Body Text Template, and assign it to the new leftSideBodyTemplate variable in your quest HUD subclass.

If you'd like to see an example scene, let me know.
rdanielson
Posts: 5
Joined: Thu Feb 17, 2022 1:18 pm

Re: Quest HUD text positioning

Post by rdanielson »

Hi Tony,

This did the trick, thank you so much for your help (and the great product)!
User avatar
Tony Li
Posts: 21928
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest HUD text positioning

Post by Tony Li »

Happy to help!
rdanielson
Posts: 5
Joined: Thu Feb 17, 2022 1:18 pm

Re: Quest HUD text positioning

Post by rdanielson »

So it appears I have a new problem with the quest nodes using these new HUD text templates :D . It seems that when I save, exit, and reload Unity, all of the text using these new templates turn blank, as if they're not saving or not being reloaded into the quest asset properly. All of the standard HUD text templates, such as Body, save and load fine. Any ideas on why this could be happening?
Before restarting Unity
Before restarting Unity
QuestMachine-1.png (29.61 KiB) Viewed 1119 times
After restarting Unity
After restarting Unity
QuestMachine-2.png (20.85 KiB) Viewed 1119 times
User avatar
Tony Li
Posts: 21928
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest HUD text positioning

Post by Tony Li »

Make sure your custom content types are in the PixelCrushers.QuestMachine namespace. Something like:

Code: Select all

namespace PixelCrushers.QuestMachine
{
    public class LeftSideTextQuestContent : BodyTextQuestContent {}
}
If the issue still happens, are there any errors or warnings in the Console window?
rdanielson
Posts: 5
Joined: Thu Feb 17, 2022 1:18 pm

Re: Quest HUD text positioning

Post by rdanielson »

Ah, you led me to the problem! It wasn't the namespace but it was a naming discrepancy between the class and the file name (LeftSideQuestContent vs LeftSideTextQuestContent). Renamed and all seems to be well now, thanks again for your help :)
User avatar
Tony Li
Posts: 21928
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest HUD text positioning

Post by Tony Li »

Glad you found the issue!
Post Reply