Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: network object pool cleanup #827

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions Assets/Scripts/Infrastructure/NetworkObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ public void OnValidate()
/// <returns></returns>
public NetworkObject GetNetworkObject(GameObject prefab, Vector3 position, Quaternion rotation)
{
return GetNetworkObjectInternal(prefab, position, rotation);
var networkObject = m_PooledObjects[prefab].Get();

var noTransform = networkObject.transform;
noTransform.position = position;
noTransform.rotation = rotation;

return networkObject;
}

/// <summary>
Expand Down Expand Up @@ -141,24 +147,6 @@ void ActionOnDestroy(NetworkObject networkObject)
// Register Netcode Spawn handlers
NetworkManager.Singleton.PrefabHandler.AddHandler(prefab, new PooledPrefabInstanceHandler(prefab, this));
}

/// <summary>
/// This matches the signature of <see cref="NetworkSpawnManager.SpawnHandlerDelegate"/>
/// </summary>
/// <param name="prefab"></param>
/// <param name="position"></param>
/// <param name="rotation"></param>
/// <returns></returns>
NetworkObject GetNetworkObjectInternal(GameObject prefab, Vector3 position, Quaternion rotation)
{
var networkObject = m_PooledObjects[prefab].Get();

var noTransform = networkObject.transform;
noTransform.position = position;
noTransform.rotation = rotation;

return networkObject;
}
}

[Serializable]
Expand Down