public void UpdateEntities() { GameObject entitiesObj = GameObject.Find("entities"); if (entitiesObj != null) { ClearGameObject(entitiesObj); } else { entitiesObj = new GameObject("entities"); } Vector3Int playerPos = DDA.playerPos(); int size = 60; Vector2Int from = new Vector2Int(playerPos.x - size, playerPos.z - size); Vector2Int to = new Vector2Int(playerPos.x + size, playerPos.z + size); Entity[] entities = DDA.GetEntities(from, to); Debug.Log("found " + entities.Length + " entities: "); foreach (var entity in entities) { Debug.Log(entity.name); string stringId; monIds.TryGetValue(entity.type, out stringId); string name = stringId == null ? "mon_unknown" : stringId; GameObject obj = new GameObject(name); obj.transform.parent = entitiesObj.transform; var pos = new Vector3(entity.loc.x, 0, entity.loc.y); obj.transform.Translate((pos - startingPoint) * tileSize); // probably should prepare GameObjects and do their clones instead var mr = obj.AddComponent <MeshRenderer>(); var mf = obj.AddComponent <MeshFilter>(); mf.sharedMesh = voxModelsCache[name].ToMesh(); mr.sharedMaterial = terrainMaterial; mf.sharedMesh.RecalculateNormals(); } }