Skip to content

Commit 82ed5ad

Browse files
committed
Fixed spawning position and rotation defaults
1 parent c54e643 commit 82ed5ad

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ internal set
125125
/// <param name="approved">Wheter or not the client was approved</param>
126126
/// <param name="position">The position to spawn the client at</param>
127127
/// <param name="rotation">The rotation to spawn the client with</param>
128-
public delegate void ConnectionApprovedDelegate(uint clientId, int prefabId, bool approved, Vector3 position, Quaternion rotation);
128+
public delegate void ConnectionApprovedDelegate(uint clientId, int prefabId, bool approved, Vector3? position, Quaternion? rotation);
129129
/// <summary>
130130
/// The callback to invoke during connection approval
131131
/// </summary>
@@ -1001,7 +1001,7 @@ private void SyncTime()
10011001
}
10021002
}
10031003

1004-
internal void HandleApproval(uint clientId, int prefabId, bool approved, Vector3 position, Quaternion rotation)
1004+
internal void HandleApproval(uint clientId, int prefabId, bool approved, Vector3? position, Quaternion? rotation)
10051005
{
10061006
if(approved)
10071007
{

MLAPI/NetworkingManagerComponents/Core/InternalMessageHandler.Receive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ internal static void HandleConnectionRequest(uint clientId, Stream stream, int c
196196
}
197197
else
198198
{
199-
netManager.HandleApproval(clientId, -1, true, Vector3.zero, Quaternion.identity);
199+
netManager.HandleApproval(clientId, -1, true, null, null);
200200
}
201201
}
202202
}

MLAPI/NetworkingManagerComponents/Core/SpawnManager.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ internal static void MarkSceneObjects()
189189
}
190190
}
191191

192-
internal static NetworkedObject CreateSpawnedObject(int networkedPrefabId, uint networkId, uint owner, bool playerObject, uint sceneSpawnedInIndex, bool sceneDelayedSpawn, bool destroyWithScene, Vector3 position, Quaternion rotation, bool isActive, Stream stream, bool readPayload, int payloadLength, bool readNetworkedVar)
192+
internal static NetworkedObject CreateSpawnedObject(int networkedPrefabId, uint networkId, uint owner, bool playerObject, uint sceneSpawnedInIndex, bool sceneDelayedSpawn, bool destroyWithScene, Vector3? position, Quaternion? rotation, bool isActive, Stream stream, bool readPayload, int payloadLength, bool readNetworkedVar)
193193
{
194194
if (networkedPrefabId >= netManager.NetworkConfig.NetworkedPrefabs.Count || networkedPrefabId < 0)
195195
{
@@ -203,7 +203,7 @@ internal static NetworkedObject CreateSpawnedObject(int networkedPrefabId, uint
203203
GameObject prefab = netManager.NetworkConfig.NetworkedPrefabs[networkedPrefabId].prefab;
204204
bool prefabActive = prefab.activeSelf;
205205
prefab.SetActive(false);
206-
GameObject go = MonoBehaviour.Instantiate(prefab, position, rotation);
206+
GameObject go = (position == null && rotation == null) ? MonoBehaviour.Instantiate(prefab) : MonoBehaviour.Instantiate(prefab, position.GetValueOrDefault(Vector3.zero), rotation.GetValueOrDefault(Quaternion.identity));
207207
prefab.SetActive(prefabActive);
208208

209209
//Appearantly some wierd behavior when switching scenes can occur that destroys this object even though the scene is
@@ -227,8 +227,6 @@ internal static NetworkedObject CreateSpawnedObject(int networkedPrefabId, uint
227227
netObject.destroyWithScene = destroyWithScene;
228228
netObject.OwnerClientId = owner;
229229
netObject.isPlayerObject = playerObject;
230-
netObject.transform.position = position;
231-
netObject.transform.rotation = rotation;
232230
netObject.SceneDelayedSpawn = sceneDelayedSpawn;
233231
netObject.sceneSpawnedInIndex = sceneSpawnedInIndex;
234232

@@ -265,7 +263,9 @@ internal static NetworkedObject CreateSpawnedObject(int networkedPrefabId, uint
265263

266264
//Normal spawning
267265
{
268-
GameObject go = MonoBehaviour.Instantiate(netManager.NetworkConfig.NetworkedPrefabs[networkedPrefabId].prefab, position, rotation);
266+
GameObject prefab = netManager.NetworkConfig.NetworkedPrefabs[networkedPrefabId].prefab;
267+
GameObject go = (position == null && rotation == null) ? MonoBehaviour.Instantiate(prefab) : MonoBehaviour.Instantiate(prefab, position.GetValueOrDefault(Vector3.zero), rotation.GetValueOrDefault(Quaternion.identity));
268+
269269
NetworkedObject netObject = go.GetComponent<NetworkedObject>();
270270
if (netObject == null)
271271
{
@@ -285,8 +285,6 @@ internal static NetworkedObject CreateSpawnedObject(int networkedPrefabId, uint
285285
netObject.destroyWithScene = destroyWithScene;
286286
netObject.OwnerClientId = owner;
287287
netObject.isPlayerObject = playerObject;
288-
netObject.transform.position = position;
289-
netObject.transform.rotation = rotation;
290288
netObject.SceneDelayedSpawn = sceneDelayedSpawn;
291289
netObject.sceneSpawnedInIndex = sceneSpawnedInIndex;
292290

0 commit comments

Comments
 (0)