# Unity Ninja Battle Tutorial - "Failed initializing runtime modules","error":"TypeError: matchSignal not found"

**URL:** <https://forum.heroiclabs.com/t/unity-ninja-battle-tutorial-failed-initializing-runtime-modules-error-typeerror-matchsignal-not-found/3138>\
**Category:** Local Setup\
**Created:** [October 5, 2022, 3:10pm UTC](https://forum.heroiclabs.com/t/unity-ninja-battle-tutorial-failed-initializing-runtime-modules-error-typeerror-matchsignal-not-found/3138 "2022-10-05T15:10:49Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Rob161](https://avatars.discourse-cdn.com/v4/letter/r/ecd19e/32.png) [@Rob161](https://forum.heroiclabs.com/u/Rob161)\
**Post date:** [December 12, 2022, 3:43pm UTC](https://forum.heroiclabs.com/t/unity-ninja-battle-tutorial-failed-initializing-runtime-modules-error-typeerror-matchsignal-not-found/3138/21 "2022-12-12T15:43:22Z")

</div>

Can do.  
Below is the code if I move a unit:

```auto
        public void Move(Tile targetTile)
        {
            Vector3 unitPos = transform.position;
            Vector3 targetPos = targetTile.transform.position;

            long opCode = (long) MultiplayerManager.Code.MoveUnit;
            string state = GetJsonPositionAndAbilityInd(unitPos, targetPos,0);
}

        public string GetJsonPositionAndAbilityInd (Vector3 selectedUnit, Vector3 targetTile, int abilityIndex)
        {
            var values = new Dictionary<string, string>
            {
                {"SelectedUnitPos.x", selectedUnit.x.ToString() },
                {"SelectedUnitPos.y", selectedUnit.y.ToString() },
                {"SelectedUnitPos.z", selectedUnit.z.ToString() },
                {"TargetTilePos.x", targetTile.x.ToString() },
                {"TargetTilePos.y", targetTile.y.ToString() },
                {"TargetTilePos.z", targetTile.z.ToString() },
                {"AbilityIndex", abilityIndex.ToString()}
            };

            return values.ToJson();
        }

```

This is the first part of the client code when receiving the match state:

```auto
        private void OnReceivedMatchState(IMatchState matchState = null)
        {
            Debug.Log("Received OpCode: "+matchState.OpCode);
            string state = Encoding.UTF8.GetString(matchState.State);
            Debug.Log("Received State: "+state);

```

In the client console I get:  
**Received OpCode: 1**  
**Received State: “{"SelectedUnitPos.x":"-3.75","SelectedUnitPos.y":"0.1","SelectedUnitPos.z":"6.4875","TargetTilePos.x":"-3.75","TargetTilePos.y":"0.1","TargetTilePos.z":"0","AbilityIndex":"0"}”**

This is the client code that is meant to perform the unit movement action when receiving this match state:

```auto
            if (matchState.OpCode == (long)Code.MoveUnit)
            {
                var stateDictionary = GetStateDictionary(matchState.State);
                Vector3 unitPos = new Vector3(float.Parse(stateDictionary["SelectedUnitPos.x"]), float.Parse(stateDictionary["SelectedUnitPos.y"]), float.Parse(stateDictionary["SelectedUnitPos.z"]));
                Vector3 targetPos = new Vector3(float.Parse(stateDictionary["TargetTilePos.x"]), float.Parse(stateDictionary["TargetTilePos.y"]), float.Parse(stateDictionary["TargetTilePos.z"]));

                UnityMainThreadDispatcher.Instance().AddActionToQueue(MoveUnit(unitPos, targetPos));
            }

        private IDictionary<string,string> GetStateDictionary(byte[] state)
        {
            return Encoding.UTF8.GetString(state).FromJson<Dictionary<string, string>>();
        }

```

The error I get in the client console is:

System.NullReferenceException: Object reference not set to an instance of an object  
at Nakama.Helpers.MultiplayerManager.OnReceivedMatchState (Nakama.IMatchState matchState) [0x00089] in C:\Unity Projects\Projects\Valorous\Assets\Nakama\Scripts\MultiplayerManager.cs:253  
at Nakama.Socket.ProcessMessage (System.ArraySegment`1[T] buffer) [0x001ed] in <127981172e4e4a2b9b7ef01979f29de9>:0 UnityEngine.Debug:LogError (object) Nakama.Socket:ProcessMessage (System.ArraySegment`1)

Note: this is what I used when I had it setup to be client to client. But seems to not work with server authorative. Unless I am just completely missing something here!

Thanks!

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [December 12, 2022, 4:08pm UTC](https://forum.heroiclabs.com/t/unity-ninja-battle-tutorial-failed-initializing-runtime-modules-error-typeerror-matchsignal-not-found/3138/22 "2022-12-12T16:08:28Z")

</div>

@Rob161 I’m confused about what triggers this error. It looks like it’s originating in our .dll but being reported from an error handler that you’ve wired up in `ReceivedError` - can you confirm that you’ve wired up this handler and tell me what triggers the error occuring?

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [December 12, 2022, 4:09pm UTC](https://forum.heroiclabs.com/t/unity-ninja-battle-tutorial-failed-initializing-runtime-modules-error-typeerror-matchsignal-not-found/3138/23 "2022-12-12T16:09:07Z")

</div>

Could you also file this as an issue on our Unity or .NET github repositories so we could discuss there instead?

---

<div class="post-metadata">

**Author:** ![Rob161](https://avatars.discourse-cdn.com/v4/letter/r/ecd19e/32.png) [@Rob161](https://forum.heroiclabs.com/u/Rob161)\
**Post date:** [December 15, 2022, 2:52pm UTC](https://forum.heroiclabs.com/t/unity-ninja-battle-tutorial-failed-initializing-runtime-modules-error-typeerror-matchsignal-not-found/3138/24 "2022-12-15T14:52:21Z")

</div>

Well in the end, I decided to write up the code from scratch again - and it now works. Still not sure where the error came from, but all I know is that it now works! But thanks for assisting with this anyway.

Couple last questions:

1. If I want to now leave matches open so players can rejoin when they like, I understand I will need to check the TS files to make sure nothing triggers the matchTerminate (such as from no moves detected for a certain amount of time). I’ll then setup a RPC function which will trigger matchTerminate if one of players presses “surrender” - and I will set this as the only way a match can be terminated. Does this seem like the way to go about this? Also, how do I go about having a player be able to pull up a list of their open matches they haven’t “surrendered” from so they can have the option to rejoin them? If there is a tutorial out there that has this covered that would be excellent.

2. My other question is, if I have already created the javascript index.js file in the modules folder from my typescript files and I need to update this server code, can I just edit the index.js file? Is there any point to update the typescript files and then run npx tsc from the Terminal to create a new index.js file?

Much appreciated.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [December 15, 2022, 6:18pm UTC](https://forum.heroiclabs.com/t/unity-ninja-battle-tutorial-failed-initializing-runtime-modules-error-typeerror-matchsignal-not-found/3138/25 "2022-12-15T18:18:27Z")

</div>

1. You can use the [match labels and the query language](https://heroiclabs.com/docs/nakama/concepts/multiplayer/query-syntax/#matching) to look up any matches the user is in. You’d use the runtime function `matchLabelUpdate` to set the user IDs of participating players in its label. You’d then lookup any ongoing matches with that specific userID when attempting to rejoin using the [match listing API](https://heroiclabs.com/docs/nakama/concepts/multiplayer/match-listing/).  
You can leave the matches running indefinitely, however this could become an issue as their respective resources will never be released so keep that in mind.  
I’d like to clarify that the [matchTerminate](https://heroiclabs.com/docs/nakama/server-framework/typescript-runtime/function-reference/match-handler/#MatchTerminate) hook is only invoked when the server receives a shut down signal, and is meant to provide a way to handle match state serialization or other tasks before the match is to be terminated.

2. You can edit the `index.js` file directly and just write your code in ES5 compliant JS, however you’d lose the niceties that come from having the Nakama TS definitions (e.g.: auto-complete in your code editor) and the general benefits of a strongly typed language. Moreover, the tsc compiler options we provide ensure that the output JS is ES5 compliant and hence supported by Nakama. I’d advise you stick to editing your TS code and transpile it as recommended, but ultimately it’s up to your development personal preferences.

---

<div class="post-metadata">

**Author:** ![Rob161](https://avatars.discourse-cdn.com/v4/letter/r/ecd19e/32.png) [@Rob161](https://forum.heroiclabs.com/u/Rob161)\
**Post date:** [December 19, 2022, 3:12pm UTC](https://forum.heroiclabs.com/t/unity-ninja-battle-tutorial-failed-initializing-runtime-modules-error-typeerror-matchsignal-not-found/3138/26 "2022-12-19T15:12:10Z")

</div>

No worries, sounds like a plan. Thanks heaps for your help on this. Appreciate it.

[Previous page](https://forum.heroiclabs.com/t/unity-ninja-battle-tutorial-failed-initializing-runtime-modules-error-typeerror-matchsignal-not-found/3138.md?page=1)
