@@ -189,7 +189,7 @@ internal static void MarkSceneObjects()
189
189
}
190
190
}
191
191
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 )
193
193
{
194
194
if ( networkedPrefabId >= netManager . NetworkConfig . NetworkedPrefabs . Count || networkedPrefabId < 0 )
195
195
{
@@ -203,7 +203,7 @@ internal static NetworkedObject CreateSpawnedObject(int networkedPrefabId, uint
203
203
GameObject prefab = netManager . NetworkConfig . NetworkedPrefabs [ networkedPrefabId ] . prefab ;
204
204
bool prefabActive = prefab . activeSelf ;
205
205
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 ) ) ;
207
207
prefab . SetActive ( prefabActive ) ;
208
208
209
209
//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
227
227
netObject . destroyWithScene = destroyWithScene ;
228
228
netObject . OwnerClientId = owner ;
229
229
netObject . isPlayerObject = playerObject ;
230
- netObject . transform . position = position ;
231
- netObject . transform . rotation = rotation ;
232
230
netObject . SceneDelayedSpawn = sceneDelayedSpawn ;
233
231
netObject . sceneSpawnedInIndex = sceneSpawnedInIndex ;
234
232
@@ -265,7 +263,9 @@ internal static NetworkedObject CreateSpawnedObject(int networkedPrefabId, uint
265
263
266
264
//Normal spawning
267
265
{
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
+
269
269
NetworkedObject netObject = go . GetComponent < NetworkedObject > ( ) ;
270
270
if ( netObject == null )
271
271
{
@@ -285,8 +285,6 @@ internal static NetworkedObject CreateSpawnedObject(int networkedPrefabId, uint
285
285
netObject . destroyWithScene = destroyWithScene ;
286
286
netObject . OwnerClientId = owner ;
287
287
netObject . isPlayerObject = playerObject ;
288
- netObject . transform . position = position ;
289
- netObject . transform . rotation = rotation ;
290
288
netObject . SceneDelayedSpawn = sceneDelayedSpawn ;
291
289
netObject . sceneSpawnedInIndex = sceneSpawnedInIndex ;
292
290
0 commit comments