Issue Updating Variable Values in Narrative Design from Unity (WebGL)

Hi,
I’m using Convai Narrative Design version 3.2.4 in a WebGL project.

I’ve created several variables (keys) in the Narrative Design editor and assigned them initial values. When the conversation starts, I send those values from Unity and they are successfully recognized by the system.

However, later in the conversation, when I try to update those same variables from Unity—based on certain user actions or events—the new values are not reflected in Narrative Design.

I’ve confirmed that the update functions are being called, as the Debug.Log messages in the Unity console show the updated values being processed and sent. Despite that, Narrative Design doesn’t seem to reflect the new values.

Why might this be happening?
Is there an additional step or limitation when syncing variable updates dynamically from Unity to Narrative Design, particularly in WebGL?

Any help or suggestions would be greatly appreciated.

void SetNarrativeDesignKey(string keyName, string keyValue)
{
if (narrativeDesignKeyController == null) return;
if (!narrativeDesignKeyController.narrativeDesignKeyController.narrativeDesignKeys.Exists(key => key.name == keyName))
{
narrativeDesignKeyController.narrativeDesignKeyController.narrativeDesignKeys.Add(new NarrativeDesignKeyController.NarrativeDesignKey { name = keyName, value = keyValue });
}
else
{
narrativeDesignKeyController.narrativeDesignKeyController.narrativeDesignKeys.Find(key => key.name == keyName).value = keyValue;
}
}

Hello @Aby,

Welcome to the Convai Developer Forum!

Which version of the WebGL SDK are you using?

Hi,

I’m currently using version 3.0.0 of the WebGL SDK, which I downloaded from the official repository:

However, in Unity’s package manager, it shows that I actually have version 3.2.4 installed.

However, I’m having trouble updating the narrative design keys through code.

Is there a recommended way to update narrative design keys and apply them correctly in WebGL builds?

Thanks in advance for your help!

You see the Asset Store version from the Package Manager.
Could you clarify when the ND Keys are being updated in your setup? Is it during the initial interaction with the character, or when the character is being enabled or disabled? Understanding this will help us assist you more accurately.

I’m currently using version 3.2.4 of the Convai Unity WebGL SDK (even though I downloaded version 3.0.0 from GitHub, the Unity Package Manager shows 3.2.4 installed).

The ND (Narrative Design) keys are meant to be updated during the interaction with the character, not just when activating or deactivating it.

For example, from Unity I set a key like this:
string textTest = "test";
Then I start a conversation with the avatar and ask for the value of that key, and it correctly replies with “new test”.

During that same interaction, I try to update the value of the key via an action in Unity. I call a function that should update the key to "prueba2", and I send the updated keys using SendNarrativeDesignKeys().

However, when I ask the avatar again for the current value, it still replies with “prueba”, as if the update didn’t take effect.
This makes me think that even though I’m calling SendNarrativeDesignKeys() with the new values, they are not being reflected in real time during the ongoing conversation in Convai WebGL.

You are not using 3.2.4. As I said, this is just Convai’s Asset Store version.

I will investigate and get back to you.

Hi

We’d like to mention that this issue is very important for our project, so we would greatly appreciate any additional help or guidance you can provide to help us resolve it as soon as possible.

Thank you again for your time and support!

You can add this method to ConvaiGRPCWebAPI.cs and call it from the code where you updated the ND key.

        public void UpdateNDKeys()
        {
            if(_currentInteractingNPC == null)
            {
                ConvaiLogger.Warn($"[{nameof(ConvaiGRPCWebAPI)}] {nameof(UpdateNDKeys)} called, but no active NPC.", ConvaiLogger.LogCategory.Character);
                return;
            }
#if UNITY_WEBGL && !UNITY_EDITOR
            // Prepare configurations
            string templateKeyJSON = GetJsonString(_currentInteractingNPC.NarrativeDesignKeyController?.narrativeDesignKeyController, "NarrativeDesign Keys");
            string actionConfigJSON = GetJsonString(_currentInteractingNPC.ActionsHandler?.ActionConfig, "Action Config");

            // Call the internal wrapper for JS client initialization
            InitializeConvaiClientWrapper(
                _currentInteractingNPC.characterID,
                enableAudioRecorder: true,
                actionConfigJson: actionConfigJSON,
                templateKeysJson: templateKeyJSON
            );
#else
            // Call wrapper even in editor to log the skip message
            InitializeConvaiClientWrapper(_currentInteractingNPC.characterID, true, "", "");
#endif
        }
2 Likes

Yes, it worked for me, thank you very much

1 Like