Quantcast
Channel: Questions in topic: "entry"
Viewing all articles
Browse latest Browse all 31

Dictionary List seems empty althought I can see entries in Debug Mode

$
0
0
Hi, I'm learning and working on a simple MMORPG. On the Client side I'm trying to create a Dictionary of all NPCs on the map with: public static Dictionary npcList = new Dictionary(); ///// [...] GameObject[] NPCgameObjects = GameObject.FindGameObjectsWithTag("NPC"); npcObjects = new Transform[NPCgameObjects.Length]; for (int i = 0; i < NPCgameObjects.Length; i++) { npcObjects[i] = NPCgameObjects[i].transform; npcList.Add((ushort)i, npcObjects[i].GetComponent()); } I can see in the Debug Mode that the Dictionary has 2 Elemenets of the 2 Goblins from the Map: ![alt text][1] [1]: /storage/temp/199929-debug.png But when I'm trying to update the NPCs position with a data from the server, it seems like trying to get a value from the NPC Dictionary List is returning "false" like it's empty: [MessageHandler((ushort)ServerToClientID.updateNPCList)] private static void UpdateNPCs(Message message) { Debug.Log("Updating NPCs....."); ushort id = message.GetUShort(); //id Vector3 cpos = message.GetVector3(); //current pos Vector3 dest = message.GetVector3(); //dest for (int i=0; i<5; i++) { Debug.Log(npcList.TryGetValue(id, out NPCController npcx)); // <- this gives FALSE all the time. if (npcList.TryGetValue(id, out NPCController npc)) { Debug.Log("NPC: " + npc.transform.name + " updating pos"); npc.agent.Warp(cpos); npc.agent.SetDestination(dest); } } } }

Viewing all articles
Browse latest Browse all 31

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>