@@ -10,6 +10,8 @@ namespace MLAPI
1010{
1111 public class NetworkingManager : MonoBehaviour
1212 {
13+ public bool DontDestroy = true ;
14+ public bool RunInBackground = true ;
1315 public List < GameObject > SpawnablePrefabs ;
1416 public GameObject DefaultPlayerPrefab ;
1517 public static NetworkingManager singleton ;
@@ -42,15 +44,28 @@ public bool isHost
4244
4345 private void OnValidate ( )
4446 {
45- for ( int i = 0 ; i < SpawnablePrefabs . Count ; i ++ )
47+ if ( SpawnablePrefabs != null )
4648 {
47- NetworkedObject netObject = SpawnablePrefabs [ i ] . GetComponentInChildren < NetworkedObject > ( ) ;
49+ for ( int i = 0 ; i < SpawnablePrefabs . Count ; i ++ )
50+ {
51+ if ( SpawnablePrefabs [ i ] == null )
52+ continue ;
53+ NetworkedObject netObject = SpawnablePrefabs [ i ] . GetComponentInChildren < NetworkedObject > ( ) ;
54+ if ( netObject == null )
55+ {
56+ Debug . LogWarning ( "MLAPI: All SpawnablePrefabs need a NetworkedObject component. Please add one to the prefab " + SpawnablePrefabs [ i ] . gameObject . name ) ;
57+ continue ;
58+ }
59+ netObject . SpawnablePrefabIndex = i ;
60+ }
61+ }
62+ if ( DefaultPlayerPrefab != null )
63+ {
64+ NetworkedObject netObject = DefaultPlayerPrefab . GetComponentInChildren < NetworkedObject > ( ) ;
4865 if ( netObject == null )
4966 {
50- Debug . LogWarning ( "MLAPI: All SpawnablePrefabs need a NetworkedObject component. Please add one to the prefab " + SpawnablePrefabs [ i ] . gameObject . name ) ;
51- continue ;
67+ Debug . LogWarning ( "MLAPI: The player object needs a NetworkedObject component." ) ;
5268 }
53- netObject . SpawnablePrefabIndex = i ;
5469 }
5570 }
5671
@@ -250,7 +265,10 @@ private void OnEnable()
250265 return ;
251266 }
252267 singleton = this ;
253- DontDestroyOnLoad ( gameObject ) ;
268+ if ( DontDestroy )
269+ DontDestroyOnLoad ( gameObject ) ;
270+ if ( RunInBackground )
271+ Application . runInBackground = true ;
254272 }
255273
256274 private void OnDestroy ( )
0 commit comments