Skip to content

Commit

Permalink
Initialize map for late joining client (#838)
Browse files Browse the repository at this point in the history
* Reinitializes Tilemap for late joining clients

* Adds a tolerance to the FindChild function.

This prevents the dreaded "Child was not found when reinitializing" error from occurring when there are minute differences in position.
  • Loading branch information
Ryan089 authored Oct 25, 2021
1 parent c1fa840 commit 5d7ee17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Assets/Engine/Server/Mirror/SceneLoaderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public void TargetSetActiveScene(NetworkConnection conn)
SceneManager.SetActiveScene(GetSelectedScene());
Debug.Log("New active scene set " + SceneManager.GetActiveScene().name);

TileManager.Instance.Reinitialize();

if (RoundManager.singleton.IsRoundStarted)
{
ServerLobbyUIHelper.singleton.ChangeEmbarkText();
Expand Down
7 changes: 6 additions & 1 deletion Assets/Engine/Tile/TileRework/TileMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class MapSaveObject
/// </summary>
private const float TILE_SIZE = 1.0f;

/// <summary>
/// The tolerance threshold for identifying a tile object at a position.
/// </summary>
private const float POSITION_TOLERANCE = 0.05f;

private Dictionary<Vector2Int, TileChunk> chunks;
public int ChunkCount { get => chunks.Count; }
public bool IsMain { get; set; }
Expand Down Expand Up @@ -566,7 +571,7 @@ private GameObject FindChild(TileLayer layer, int subLayerIndex, Vector3 positio
var child = layerObjectTransform.GetChild(i);

// There can be small offsets in height for some objects like overlays, so use only X and Z
if (child.position.x == position.x && child.position.z == position.z)
if ((Math.Abs(child.position.x - position.x) < POSITION_TOLERANCE) && (Math.Abs(child.position.z - position.z) < POSITION_TOLERANCE))
{
if (sameTile && !child.name.Contains("_" + subLayerIndex))
continue;
Expand Down

0 comments on commit 5d7ee17

Please sign in to comment.