Page 1 of 1

Lag during first time setting a quest state

Posted: Mon May 01, 2017 8:27 am
by fringilla
Hi!
I've just noticed that when I play built game there's a 2-5 seconds lag when first setting a quest state. I have a conversation and in the last entry of it I run Lua code:
SetQuestState("main_1", "active");
SetQuestEntryState("main_1", 1, "active");
and this is where I have a lag which is different depending on a computer perfomance.
I have ticked "Preload Resources" on a Dialogue System Controller.
Do you have an idea where does this lag come from?

Re: Lag during first time setting a quest state

Posted: Mon May 01, 2017 11:56 am
by Tony Li
Hi,

Does the lag also occur in the editor? If so, it's easier to debug in the editor because you can look at the Console window. If it only happens in builds, please review the player log instead.

In either case, look for any errors or warnings. Also, if you have a custom script that runs when quest states are changed, this may be causing the lag. Even if it's not throwing any errors or warnings, if it writes a lot to the Debug.Log it can cause lag.

Another thing to try is to delete the quest tracker HUD from your scene if you have one. (Keep a copy of your original scene.) Then try to reproduce the problem. If the lag is gone, the problem might be with the quest tracker HUD.

If none of that helps, please feel free to send an example project to tony (at) pixelcrushers.com and let me know what version of Unity to use and what platform to build for.

Re: Lag during first time setting a quest state

Posted: Tue May 02, 2017 5:22 pm
by fringilla
Hi Tony! Thanks you for your reply.
To answer your question - the lag doesn't occur in the editor. That's why I didn't noticed it sooner probably! There's nothing interesting in the log.
I have gathered some more info about this lag:
1. I think this is actually an issue connected to the Tracker UI. I am using Unity UI Quest Tracker. If I make this first quest active in the dialogue database instead of during the end of the first conversation there's a short lag at the end of the loading string but no lag later.
2. If I make this quest active at the end of the first conversation but don't track it on start so the tracker doesn't appear, there is no lag.
3. However, if I take another quest which is trackable on start and the tracker appears there is still no lag :O So this only happens during the first conversation.
4. I am almost sure this is not caused by something still loading at the start of the game because even if I was waiting a few minutes before going on with that first conversation, the lag was still occurring.
5. This is interesting - the lag is the longest with the first execution of a particular build. Even when I quit a game and play it again, the lag will be noticeably shorter than it was the first time.
6. I commented out all of mine code that has somehow tracked any quest states and the lag is still there.
7. I am running the lua code on the last entry of the conversation and the lag occurs between the last and the previous one (after I click a continue button on a previous one).

Unfortunately, I can't email you the project because you know, it isn't supposed to be seen... yet :P
Sorry for my English and thank you in advance for any help because, honestly, I am running out of ideas what may cause this lag!

Re: Lag during first time setting a quest state

Posted: Tue May 02, 2017 9:15 pm
by Tony Li
Hi,

What platform and device are you building for? I tested on a Windows 10 PC build and an Android build for an Azpen quad core 1.3Ghz tablet, and I couldn't reproduce the issue.

As a test, what if you try using the Generic Unity UI Quest Tracker HUD prefab instead of your quest tracker? Is the lag still there?

It's possible that the Just-In-Time (JIT) compiler for your build platform is loading code when the first quest is tracked, or that Unity is loading the textures or other resources for the quest track template.

As a last resort, you could pre-warm the quest tracker by adding the script below to it. When the game starts, it will invisibly add a quest for 1 frame and then remove it.

PrewarmQuestTracker.cs

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;

[RequireComponent(typeof(UnityUIQuestTracker))]
public class PrewarmQuestTracker : MonoBehaviour
{

    IEnumerator Start()
    {
        var tracker = GetComponent<UnityUIQuestTracker>();
        var container = tracker.container;
        var canvasGroup = container.GetComponent<CanvasGroup>();
        if (canvasGroup == null) canvasGroup = container.gameObject.AddComponent<CanvasGroup>();
        canvasGroup.alpha = 0;
        container.gameObject.SetActive(true);
        QuestLog.GetAllQuests();
        var go = Instantiate(tracker.questTrackTemplate.gameObject) as GameObject;
        go.transform.SetParent(container.transform, false);
        var questTrack = go.GetComponent<UnityUIQuestTrackTemplate>();
        questTrack.SetDescription("Initializing...", QuestState.Active);
        yield return null;
        Destroy(go);
        container.gameObject.SetActive(false);
        canvasGroup.alpha = 1;
    }
} 

Re: Lag during first time setting a quest state

Posted: Wed May 03, 2017 9:47 am
by fringilla
I am testing on a notebook with Win 10. Other people from my team have tested it on PCs (one second lag or none) and other notebooks (1-5 seconds lag).

After adding your script I have the same lag but visible on the loading screen.

My tracker is basically the Generic Unity UI Tracker with visual changes so it doesn't really matter (I've tried tho and nothing has changed).

I know you can't really do anything more to help. I will talk to my team about sending you our project :)

Re: Lag during first time setting a quest state

Posted: Wed May 03, 2017 10:15 am
by Tony Li
Yes, the script above isn't a fix; it's just a workaround to move the lag to the loading screen instead of gameplay.

All customer files are treated confidentially. If your team is okay with it, I can assure you that your files will be kept private.

Re: Lag during first time setting a quest state

Posted: Fri May 05, 2017 8:13 am
by fringilla
I've sent you an email with a link to the Google drive folder.

I'm even more confused now. I've tried to start a coroutine after the first dialogue in OnConversationEnd, wait a few seconds and set the quest state active. And the lag occured. Then I turned off setting this quest state during or after the first conv and immiediately after the first conv started talking to the npc and setting the quest active in this dialogue. No lag. What the heck...?

Re: Lag during first time setting a quest state

Posted: Fri May 05, 2017 9:37 am
by Tony Li
Hi,

I got your email. I'll download the project and let you know what I find.