Hello, I'm trying to get a few NPCs to roam across the map in my game. They'll have a variable inside their Actor that says where their current location is. The way I'm checking it is whether or not the NPC's location (which changes based on conversations) is the same as the player's and if so, it activates the NPC.
The reason it's being done like this is because the game and NPCs are all spread across multiple scenes, so we don't want any reference problems.
I tried a quick C# script to test this, but so far it either seems to always return false, even if I manually set the two Location variables to be the same.
Is there a difference in how the variables are called? I thought they were both Locations, so it would be okay to compare them as strings, but apparently something is wrong.
Maybe the variables aren't being immediately set up? Those debug logs I set both return empty.
Any ideas on how I could fix this?
Setting an NPC active depending on location.
Re: Setting an NPC active depending on location.
Hi,
Location variables/fields store the location's ID number -- 2 in the case of Basecamp [2].
Check:
Are you sure the database with those variables/fields is loaded into memory (e.g., assigned to the Dialogue Manager's Initial Database field)?
Location variables/fields store the location's ID number -- 2 in the case of Basecamp [2].
Check:
Code: Select all
Debug.Log("CurrentLocation: " + DialogueLua.GetVariable("CurrentLocation").asInt);
Re: Setting an NPC active depending on location.
Hello, thanks for the help! At least now I can check the numbers correctly on Debug.
Interestingly, both the actor's CurrentLocation and the Player's CurrentLocation are returning 0 at start, even though they've been manually set to 2. Maybe it has to do with me invoking the function on Enable? There might be some configuration that briefly resets the variables at start (thus making them read as 0), no?
Ah, I can also confirm that the database used on the scene is indeed the correct one.
Interestingly, both the actor's CurrentLocation and the Player's CurrentLocation are returning 0 at start, even though they've been manually set to 2. Maybe it has to do with me invoking the function on Enable? There might be some configuration that briefly resets the variables at start (thus making them read as 0), no?
Ah, I can also confirm that the database used on the scene is indeed the correct one.
Re: Setting an NPC active depending on location.
Hi,
Try waiting a frame for the database to populate Lua.
Try waiting a frame for the database to populate Lua.
Re: Setting an NPC active depending on location.
So, holding for a frame using a coroutine worked. It now returns the correct value.
However, I do have to ask: this means that the values on the Database are all being returned to 0 after Start and then are set to whatever value I assign to them, right? Is there a way I can change this?
P.S.: Additionally, we realized that a similar limitation is set upon the save system. Is it a general thing we have to be aware of when invoking the database variables?
However, I do have to ask: this means that the values on the Database are all being returned to 0 after Start and then are set to whatever value I assign to them, right? Is there a way I can change this?
P.S.: Additionally, we realized that a similar limitation is set upon the save system. Is it a general thing we have to be aware of when invoking the database variables?
Re: Setting an NPC active depending on location.
Here is the order in which things happen:
Awake:
Or hook into DialogueManager.instance.initializationComplete:
In version 2.2.16, I've added a refactor that loads the Initial Database content into Lua by the end of Awake, so it will be available in OnEnable and Start. It isn't that way in 2.2.15 because of some preloading code. The Dialogue Manager's Other Settings > Preload Resources will still work, however.
Awake:
- Dialogue Manager does basic initialization but not database.
- Dialogue Manager loads database content into Lua and registers Lua functions.
- Dialogue Manager prewarms UI if specified in Other Settings.
- DialogueManager.instance.initializationComplete event invoked.
Code: Select all
IEnumerator Start()
{
yield return new WaitForEndOfFrame();
// (Your code here that accesses Lua variables.)
}
Code: Select all
void Awake()
{
DialogueManager.instance.initializeComplete += OnInitialized;
}
void OnInitialized()
{
DialogueManager.instance.initializeComplete += OnInitialized;
// (Your code here that accesses Lua variables.)
}
In version 2.2.16, I've added a refactor that loads the Initial Database content into Lua by the end of Awake, so it will be available in OnEnable and Start. It isn't that way in 2.2.15 because of some preloading code. The Dialogue Manager's Other Settings > Preload Resources will still work, however.