Page 2 of 3

Re: Referencing Actors and fields in custom script

Posted: Tue Jun 22, 2021 4:53 pm
by Tony Li
If you step forward once more so that the yellow line is on the "if" statement, is talkLvl updated to1?

Re: Referencing Actors and fields in custom script

Posted: Tue Jun 22, 2021 4:57 pm
by annathehank
Well....my Unity had a lil conniption fit so I had to force quit and load back up.
And now when I play it it works perfectly...

I'll keep you updated but hopefully, it was just a weird glitch?

Re: Referencing Actors and fields in custom script

Posted: Tue Jun 22, 2021 5:04 pm
by Tony Li
It might've just been Unity bugging out. Anyway, glad it's working now!

Re: Referencing Actors and fields in custom script

Posted: Tue Jun 22, 2021 5:11 pm
by annathehank
Me too! Thank you very much for the help <3

Re: Referencing Actors and fields in custom script

Posted: Tue Jun 22, 2021 5:22 pm
by Tony Li
Glad to help!

Re: Referencing Actors and fields in custom script

Posted: Mon Aug 23, 2021 2:19 pm
by annathehank
Hi, hope it's okay to revive this again, as I still don't think it's working properly even after playing around with it a bit more.

It sometimes does and sometimes doesn't show the alert. And when I run it as it is I get the Nullreferenceobject alert for this line

Code: Select all

foreach (Actor NPC in DialogueManager.masterDatabase.actors)
Here's what the code looks like right now:

Code: Select all

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

public class charalert : MonoBehaviour
{//Alert notification to display on map screen
    public GameObject AlertNotif;

    void Update()
    {
      
        //cycling through each actor component)
        foreach (Actor NPC in DialogueManager.masterDatabase.actors)
        {//Look to see if the level of relationship matches the conversation level player is on
            int RelLvl = DialogueLua.GetActorField(NPC.Name, "RelLvl").asInt;
            int TalkLvl = DialogueLua.GetActorField(NPC.Name, "TalkLvl").asInt;
            if ((TalkLvl*10)>= RelLvl)
            {//display altert notification on map screen
               Transform actorTransform = PixelCrushers.DialogueSystem.CharacterInfo.GetRegisteredActorTransform(NPC.Name);
                if (actorTransform != null)
                {
                    actorTransform.GetComponent<charalert>().AlertNotif.SetActive(true);
                }
               
            }
        }
    }

    // Update is called once per frame
    
}
I'm wondering if it's the name of the variable being used for the Actors?

Re: Referencing Actors and fields in custom script

Posted: Mon Aug 23, 2021 3:09 pm
by Tony Li
Hi,

Do you see just one NullReferenceException error or multiple?

After these 2 lines:

Code: Select all

if ((TalkLvl*10)>= RelLvl)
{//display alert notification on map screen
try adding this extra line:

Code: Select all

[code]if ((TalkLvl*10)>= RelLvl)
{//display alert notification on map screen
    Debug.Log("About to show alert notification for " + NPC.Name); //<--ADD THIS
Does the Console window consistently show that Debug.Log message when it's supposed to?

If so, then the issue is below that line. Maybe it's not finding the GameObject.

If it doesn't show that Debug.Log message, then we can look at the field values.

Re: Referencing Actors and fields in custom script

Posted: Wed Sep 01, 2021 11:37 am
by annathehank
I never see a log for that. It just constantly generates this error

NullReferenceException: Object reference not set to an instance of an object
charalert.Update () (at Assets/Scripts/charalert.cs:14)

And when I click on them they cycle through the npc assets loaded into the scene(each of which has the script on them to allow me to add the alert notif image for them in the right place.

Re: Referencing Actors and fields in custom script

Posted: Wed Sep 01, 2021 12:06 pm
by annathehank
Strike that.
I do see the log for those (I had the dialogue editor turned off when I was checking this time around. But it still seems like the alerts are not working, I get a lot of about to show alert notifs for each npc but nothing else.)
For example, when I load up the scene, all of the values should be set to match, yet only one pops up.

Re: Referencing Actors and fields in custom script

Posted: Wed Sep 01, 2021 1:58 pm
by Tony Li
Hi,

So you see "About to show alert notification for X" in the Console every time you expect, but the NPC's AlertNotif doesn't always become active when it should?

If that's the case, add these 2lines:

Code: Select all

if (actorTransform != null)
{
    Debug.Log("About to set AlertNotif active on " + actorTransform, actorTransform); //<--ADD
    actorTransform.GetComponent<charalert>().AlertNotif.SetActive(true);
}
else
{
    Debug.LogWarning("There is no registered transform for the actor named " + NPC.Name); //<--ADD
}
Then reproduce the issue.
  • If you see "About to set AlertNotif active on X" but you don't see the AlertNotif, then maybe something in your charalert script is immediately deactivating or, or maybe it's not visible somehow (e.g., renderer disabled) even though the GameObject is active.
  • If you see "There is no registered transform..." then at the point this code has run, no Dialogue Actor component has registered itself with the Dialogue System under the specified actor name.
Also, feel free at any point to send a reproduction project to tony (at) pixelcrushers.com if you like. I'll be happy to take a look.