@@ -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