Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Bug CurrentPage is NULL

Discussion in 'In-Editor Tutorials Packages' started by CaseyHofland, Mar 14, 2023.

  1. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    629
    I'm trying to create a tutorial with the tutorial authoring package. Usually this is a pleasant experience, however today it just won't work right.

    When I press a tutorial from my tutorial container, it should open the first page, but the whole day, no matter what I try, it keeps giving a Null Reference Exception. I have tried with different scriptable objects, reinstalling the tutorial framework, installing different tutorials to see if the problem persists (it does) - nothing works.

    The full stack trace is below but basically: TutorialController.DeInitializeTutorial calls CurrentTutorial.CurrentPage, which throws a null reference exception. I could fix it but then the problem will just persist in other projects I'd imagine. I have added no code of my own yet, I first wanted to write my whole tutorial out. The tutorial I'm switching to has pages assigned: this is not my first tutorial, I know how to set them up.

    This stupid grmlbrmtlbmr bug has unfortunately ruined all my productivity for the day and I can't continue until it is fixed. I welcome any advice as to how to approach this issue.

    Full Error.png

    Unity 2022.2.2
    Tutorial Framework 3.1.3
    (likely irrelevant) Tutorial Authoring Tools 1.2.2
     
  2. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    629
    I was creating the tutorial on a separate branch on our project, but making it in an entirely different project sidesteps the issue. It's not a great solution, but it works.

    Edit:
    Nevermind, it broke on this new project as well.

    Is there a github where I can create PRs?
     
    Last edited: Mar 16, 2023
  3. Ali-Unity3D

    Ali-Unity3D

    Unity Technologies

    Joined:
    Mar 8, 2021
    Posts:
    24
    The project is not developed in public GitHub but you should be able to open a bug report using the regular Unity bug tracker and it should make its way to the current maintainers of the packages.
     
  4. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,236
    Did you ever get this figured out? I was making good headway on a tutorial when I now am getting this as well. It seems to have started as soon as I right-clicked on one of my TutorialPages and hit the Properties option to open it in a floating window so I didn't have to try and keep going back and forth between inspectors. Ever since I did that, I am getting the same TutorialController null reference exception.

    No amount of editor restarts, reimporting of the package, etc, seems to fix it.

    If there is no clear resolution, I will probably just see if I can make a copy of the package for the time being and fix it locally so I can at least continue on.

    --- Edit
    I got it working again by making it a local package, then adding additional checks in each place there ended up being an error. This was the final one I got to in which it let me reset the status of the tutorials and the whole thing started working again.

    I have pages with no Paragraphs because for some steps in my tutorial I create a new blank page and hijack the rootVisualElement using the 'Shown' events and add my own elements. There are no error checks in a number of places in which there probably should.

    Code (CSharp):
    1. // TutorialPage.cs
    2. internal void ResetUserProgressAndCompletionCriteria()
    3. {
    4.     // Added the following check
    5.     if (Paragraphs == null || Paragraphs.Count == 0) { return; }
    6.  
    7.     foreach (var paragraph in Paragraphs)
    8.     {
    9.         if (paragraph.Type != ParagraphType.Instruction) { continue; }
    10.         foreach (var criterion in paragraph.Criteria)
    11.         {
    12.             if (criterion != null && criterion.Criterion != null)
    13.             {
    14.                 criterion.Criterion.Completed.RemoveAllListeners();
    15.                 criterion.Criterion.Invalidated.RemoveAllListeners();
    16.                 criterion.Criterion.StopTesting();
    17.                 criterion.Criterion.ResetCompletionState();
    18.             }
    19.         }
    20.     }
    21.  
    22.     HasMovedToNextPage = false;
    23. }
    24.  
    Then I also added the following, as I didn't realize that I had deleted a TutorialPage to use a different type and it left a blank entry in that sections main tutorial asset.

    Code (CSharp):
    1. // Tutorial.cs      
    2. internal void RaisePageInitiated(TutorialPage page, int index)
    3. {
    4.     // Added the following check
    5.     if (!page)
    6.     {
    7.         Debug.LogError("TutorialPage is null. Check the Tutorial asset.");
    8. #if UNITY_EDITOR
    9.         EditorGUIUtility.PingObject(this);
    10. #endif
    11.         return;
    12.     }
    13.  
    14.     page.Initiate();
    15.     PageInitiated?.Invoke(this, page, index);
    16. }
    17.  
    18.  
    Hopefully if anyone else comes across this issue, it might help.
     
    Last edited: Jun 26, 2023
    CaseyHofland likes this.
  5. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    629
    I wish we could just contribute for this very reason.
    Here’s a nice tip:
    Code (CSharp):
    1. // change this:
    2.         Debug.LogError("TutorialPage is null. Check the Tutorial asset.");
    3.         #if UNITY_EDITOR
    4.         EditorGUIUtility.PingObject(this);
    5.         #endif
    6.  
    7. // to this:
    8.         Debug.LogError("TutorialPage is null. Check the Tutorial asset.", this);
    9.  
    This makes it so the object gets pinged once you click on the error in the console and more closely follows Unity standards.
     
  6. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,236
    Yeah, good call. You are definitely right. I was just in a rush to get it figured out so I could keep at it and not lose steam, lol.