Referencing Actors and fields in custom script
Re: Referencing Actors and fields in custom script
If you step forward once more so that the yellow line is on the "if" statement, is talkLvl updated to1?
-
- Posts: 95
- Joined: Sun May 03, 2020 2:17 pm
Re: Referencing Actors and fields in custom script
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?
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
It might've just been Unity bugging out. Anyway, glad it's working now!
-
- Posts: 95
- Joined: Sun May 03, 2020 2:17 pm
Re: Referencing Actors and fields in custom script
Me too! Thank you very much for the help <3
Re: Referencing Actors and fields in custom script
Glad to help!
-
- Posts: 95
- Joined: Sun May 03, 2020 2:17 pm
Re: Referencing Actors and fields in custom script
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
Here's what the code looks like right now:
I'm wondering if it's the name of the variable being used for the Actors?
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)
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
}
Re: Referencing Actors and fields in custom script
Hi,
Do you see just one NullReferenceException error or multiple?
After these 2 lines:
try adding this extra line:
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.
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
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
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.
-
- Posts: 95
- Joined: Sun May 03, 2020 2:17 pm
Re: Referencing Actors and fields in custom script
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.
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.
-
- Posts: 95
- Joined: Sun May 03, 2020 2:17 pm
Re: Referencing Actors and fields in custom script
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.
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
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:
Then reproduce the issue.
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
}
- 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.