Forum rules - please read before posting.

Custom Unity UI control

2»

Comments

  • Yes. I clicked apply to apply the changes to the canvas Prefab, then deleted the canvas in the scene. Should I let the canvas stays in the scene?
  • No, it needs to be out of the scene.

    This script tweaks things to show a little debug info.  What does the Console say?
    http://pasteall.org/953139/csharp

    Then inside PlayerMenus.cs, and find the GetMenuWithCanvas method (around line 2761), and insert the following at the top of it:

    Debug.Log ("DupMenus: " + dupSpeechMenus.Count + ", Menus: " + menus.Count);

    What's the full output of the Console at the time the error occurs?  Also, if you unpause Unity after the error shows for the first time, what happens the next time a speech line is played?


  • I found when using "Duplicate for each line?", there is not NullPointException. But the problem is the Dummy Text cannot get the subtitle text, and thus cannot set the Panel (for the subtitle background) to the correct size.

    The 2 Debug.Log() gives these responses when subtitle pops up:

    DupMenus: 1, Menus: 15
    UnityEngine.Debug:Log(Object)
    AC.PlayerMenus:GetMenuWithCanvas(Canvas) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2763)
    UpdateDummyText:OnEnable() (at Assets/Ricky/Prefabs/CustomUI/CustomSubtitles/UpdateDummyText.cs:15)
    UnityEngine.GameObject:SetActive(Boolean)
    AC.Menu:EnableUI() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:555)
    AC.Menu:LoadUnityUI() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:379)
    AC.PlayerMenus:AssignSpeechToMenu(Speech) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2235)
    AC.Dialog:StartDialog(Char, String, Boolean, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Speech/Dialog.cs:144)
    AC.ActionSpeech:StartSpeech() (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:485)
    AC.ActionSpeech:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:119)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:347)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:522)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:440)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:409)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

    and

    Canvas: Canvas (UnityEngine.Canvas)Menu:  (AC.Menu)
    UnityEngine.Debug:Log(Object)
    UpdateDummyText:OnEnable() (at Assets/Ricky/Prefabs/CustomUI/CustomSubtitles/UpdateDummyText.cs:16)
    UnityEngine.GameObject:SetActive(Boolean)
    AC.Menu:EnableUI() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:555)
    AC.Menu:LoadUnityUI() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:379)
    AC.PlayerMenus:AssignSpeechToMenu(Speech) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2235)
    AC.Dialog:StartDialog(Char, String, Boolean, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Speech/Dialog.cs:144)
    AC.ActionSpeech:StartSpeech() (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:485)
    AC.ActionSpeech:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:119)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:347)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:522)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:440)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:409)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

  • You previously said there was a NRE error on line 15, which suggests the issue was with the menu variable - not speech (which there is a null-check for).

    Were you using this previously without the duplicate-line option?  As you'd said a need for it earlier, this script is only compatible with that option.

    What is the exact error message you're getting in the Console?
  • edited May 2018
    Yep, I previously got the error without the duplicate-line option. The error is:

    NullReferenceException: Object reference not set to an instance of an object
    UpdateDummyText.OnEnable () (at Assets/Ricky/Prefabs/CustomUI/CustomSubtitles/UpdateDummyText.cs:17)
    UnityEngine.Object:Instantiate(Canvas)
    AC.Menu:LoadUnityUI() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:368)
    AC.PlayerMenus:RebuildMenus(MenuManager) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:133)
    AC.PlayerMenus:OnStart() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:89)
    AC.StateHandler:InitPersistentEngine() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:97)
    AC.StateHandler:OnAwake() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:77)
    AC.KickStarter:SetPersistentEngine() (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:130)
    AC.KickStarter:OnAwake() (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:994)
    AC.MultiSceneChecker:Awake() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:47)

    When using the script with the duplicate-line option, there is no NRE error. But the problem of my previous reply exist. I think maybe I can resort to having only 1 speech bubble at a time, and use the first solution without the duplicate-line option.
  • The speech variable should be assigned to the duplicated menu on creation.  It works fine for me, so I can't see why it wouldn't be for you.

    Try this: open Menu.cs, and find the method SetSpeech (around line 2714).  Just above the line "speech = _speech;", insert the following:

    Debug.LogWarning ("Assigning speech: " + _speech);
    if (_speech != null) Debug.LogWarning ("Speech text: " + _speech.log.fullText);

    What's the output of the Console then?
  • When a dialog pops up, it shows:

    Assigning speech: AC.Speech
    UnityEngine.Debug:LogWarning(Object)
    AC.Menu:SetSpeech(Speech) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:2715)
    AC.PlayerMenus:AssignSpeechToMenu(Speech) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2238)
    AC.Dialog:StartDialog(Char, String, Boolean, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Speech/Dialog.cs:144)
    AC.ActionSpeech:StartSpeech() (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:485)
    AC.ActionSpeech:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:119)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:347)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:522)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:440)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:409)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

    and

    Speech text: Where am I?......How did I get here?
    UnityEngine.Debug:LogWarning(Object)
    AC.Menu:SetSpeech(Speech) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/Menu.cs:2716)
    AC.PlayerMenus:AssignSpeechToMenu(Speech) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2238)
    AC.Dialog:StartDialog(Char, String, Boolean, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Speech/Dialog.cs:144)
    AC.ActionSpeech:StartSpeech() (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:485)
    AC.ActionSpeech:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionSpeech.cs:119)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:347)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:522)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:440)
    AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:409)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
  • What about the other Console messages?  Where do they show in relation to the above two?

    The two new messages are exactly as they should be.  I think we could go on forever trying to debug like this, because - like I said - it works for me.

    Create a .unitypackage file of your 8 Manager assets, UI Canvas prefabs and the custom script you've attached to the Canvas in question - then PM it to me.
  • Finally managed to solve it! The issue is really in the script (as you hinted in the PM):

    I used a script of sizeDelta to resize of the subtitle text background according to the dummy text size. The sizeDelta part always works but it somehow puts the subtitle menu panel above the anchor point (which is at top-left so the entire subtitle menu cannot be seen in game). This is solved by using the Move with character? option.

    One finding is when the subtitle position is chosen to be Above Player the subtitle is always at the correct position even without the Move with character? option. I needed it because I have chosen the Above Speaking Character option.

    Thanks for the extensive help again!
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.