How to modify "Preloaded Assets" of player settings programmatically in editor script?

How to modify “Preloaded Assets” of player settings programmatically in editor script?

PlayerSettings.SetPreloadedAssets in now in the API

AFAIK, there’s no editor API that allows editing of the “Preloaded assets” array. You can achieve the same via the more generic SerializedObject and SerializedProperty APIs though:

Here’s an example of how this can be done:

var playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>();
SerializedObject so = new SerializedObject(playerSettings);

var preloadedAssets = so.FindProperty("preloadedAssets");

if (preloadedAssets != null && preloadedAssets.isArray)
	// Update preloadedAssets here
	preloadedAssets.arraySize = 1; // set the array size to whatever you wish
	// Get the array element at the given index
	var sp = preloadedAssets.GetArrayElementAtIndex(0);

	// set it to whatever object reference you wish
	sp.objectReferenceValue = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/Textures/blabla.png");