Search Unity

RPG Starter kit and Event Action reference not being set

Discussion in 'Editor & General Support' started by MrMajorThorburn, Jan 19, 2021.

  1. MrMajorThorburn

    MrMajorThorburn

    Joined:
    Dec 15, 2014
    Posts:
    89
    In the RPG Starter kit I am using there is a DialogueUI script in the Dialogue object prefab.
    A specific instance of a Dialogue in the Assets Game Dialogue folder is added to a NPC (guard in this case).
    I thought that when the game starts and this NPC is instantiated the referenced Dialogue script should run.
    This script adds a reference to its UpdateUI function to the SystemEvent Action established by the AIConversation script that is triggered by the mouse when clicked on the NPC.
    I am getting a null reference exception on the event variable.
    I have added a Debug.Log entry in the Start of the DialogueUI but that does not get run so I am confused.
    Can someone confirm that a reference to an object in the Assets Game Dialogue folder added to a gameObject in the scene will be run at game run time.

    I have tried the following. An empty gameObject in the scene has a script attached to it that instantiates a sphere that is public and has been initialised from a prefab of a sphere that has a script attached to it. In that script there is a Debug.Log that has a string in it.
    I also placed an instance of the sphere in the scene (representing an NPC) and renamed is SceneSphere.
    When I play this the contents of the strings from the spheres appear in the console.
    One as SceneSphere and the other Sphere (clone).

    The RPG has a NPC (gameobject) that has a script that contains a public Dialogue that was initialised from a dialogue object in the Assets, Game folder. That object has a reference to a script that has in its Start a statement that contains a Debug.Log containing a string. That string does Not appear in the console output.
    The Dialogue class is based on ScriptableObject.
    So it looks like Scriptable Objects when established do not call their attached scripts.
    So my question is why?
     
    Last edited: Jan 21, 2021
  2. MrMajorThorburn

    MrMajorThorburn

    Joined:
    Dec 15, 2014
    Posts:
    89
    Ok so far I have concluded that the DialogueUI script is not being run.
    That script adds the UpdateUI function to the onConversationUpdated event callbacks.
    So my question now is when is the DialogueUI supposed to get run?
    Is there any way to force this script to be run at the time the NPC gets instantiated?
     
  3. MrMajorThorburn

    MrMajorThorburn

    Joined:
    Dec 15, 2014
    Posts:
    89
    Right found my problem and the solution.
    The reason the null reference was coming up was because I had forgotten after accidentally deleting the Dialogue GameObject in the UI Canvas I had omitted the addition of the DialogueUI script that resides in the Asset/Game/UI folder. Once that was added the running of the Start in the DialogueUI was triggered when the Instance of the Dialogue was created as part of the process of clicking the NPC.