Disabling alert cross scene

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
mandi
Posts: 77
Joined: Wed Sep 16, 2015 4:05 am

Disabling alert cross scene

Post by mandi »

Hello Tony,
how to disable alerts completely? I have this strange behaviour - when I load new scene, an alert appears pertaining to the object killed in the previous (I guess).

Best!
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disabling alert cross scene

Post by Tony Li »

Hello Artur,

To disable alerts, make them invisible. If you're using Unity UI, one way is to leave the Alert Panel's Canvas Group > Alpha at 0, remove the Animator component, and on the Unity UI Dialogue UI component set the Show and Hide animation names to blank strings.

However, the reason for the strange behavior is probably a component that fires when its object is destroyed, such as Increment On Destroy. This component is frequently used to keep track of kills in a kill quest. When you "kill" the GameObject and destroy it, this component increments a Dialogue System variable and shows an alert message.

However, when you unload the previous scene, this also destroys all of its objects. The solution in this case is to call PersistentDataManager.LevelWillBeUnloaded() before loading the new scene. This tells components like Increment On Destroy to ignore the next "OnDestroy" message.

If you use the LevelManager.LoadLevel() or the LoadLevel() sequencer command to change levels, it automatically calls PersistentDataManager.LevelWillBeUnloaded() for you.
mandi
Posts: 77
Joined: Wed Sep 16, 2015 4:05 am

Re: Disabling alert cross scene

Post by mandi »

Tony,
yes, I had the UI disabled, and suspected an event fired on destroy was being picked up by the alert system. PersistentDataManager.LevelWillBeUnloaded() is the fix I need, I guess :)

Thanks!
ludm
Posts: 11
Joined: Tue May 05, 2020 3:11 pm

Re: Disabling alert cross scene

Post by ludm »

I was looking for a solution to toggle the visibility of the subtitle panel with a button. I wanted to keep the animation on the panel. So the trick was to use the Hide and Show animations when (de)activating. Here is a solution to achieve this:

Code: Select all

[SerializeField] protected GameObject subTitleGo;
Get the animator:

Code: Select all

subTtlAnim = subTitleGo.GetComponent<Animator>();

Show the panel:

Code: Select all

subTitleGo.SetActive(true);
subTtlAnim.SetTrigger("Show");

Hide the panel:

Code: Select all

subTtlAnim.SetTrigger("Hide");
subTitleGo.SetActive(false);
ludm
Posts: 11
Joined: Tue May 05, 2020 3:11 pm

Re: Disabling alert cross scene

Post by ludm »

One limitation is that it works only if the panel has been displayed once.
Do you know how I could get over this limitation ?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disabling alert cross scene

Post by Tony Li »

Hi,

You can change your animator controller.

The basic Canvas Group Animator Controller has three states: Start (hidden), Show, and Hide.

The Show and Hide trigger parameters link from Any State to the Show and Hide states.

You could change this so nothing links from Any State. Example:

alternateShowHideAnimator.png
alternateShowHideAnimator.png (21.09 KiB) Viewed 697 times

The magenta Show and Hide indicate the trigger parameters that trigger the transitions above. "Default" means is triggers automatically. Please these at the bottom of the transition list so they only take effect if the Show or Hide trigger parameters aren't set.
ludm
Posts: 11
Joined: Tue May 05, 2020 3:11 pm

Re: Disabling alert cross scene

Post by ludm »

Thanks,
I have change the animator, but I still have a problem:
When I try to hide subTtlAnim.SetTrigger("Hide"); in Start(), it throws a nullReferenceException
subTitleGo.SetActive(false); seems to be ok
But, then I start the conversation, the panel is displayed, even if subTitleGo.SetActive(false) has been set. Maybe one function in Dialogue System setActive to true when beginning the conversation.

Finally like you mentioned in another thread, I used

Code: Select all

DialogueManager.displaySettings.subtitleSettings.showNPCSubtitlesDuringLine
Like this:
Add

Code: Select all

using PixelCrushers.DialogueSystem;

Code: Select all

 DialogueManager.displaySettings.subtitleSettings.showNPCSubtitlesDuringLine = true;
subTitleGo.SetActive(true);
subTtlAnim.SetTrigger("Show");

Code: Select all

 try
{
    subTtlAnim.SetTrigger("Hide");
}
     catch (Exception e)
{
    Debug.Log("not loaded yet");
}
DialogueManager.displaySettings.subtitleSettings.showNPCSubtitlesDuringLine = false;
subTitleGo.SetActive(false);
So it works well with the original animator and these codes
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disabling alert cross scene

Post by Tony Li »

Hi,

Can you click on the error message, press Ctrl+C, and paste it in here please?
Post Reply