I’m working on a Unity project where I have a list of Waypoints objects that are populated in the Unity Editor using a custom script. The list is populated at design time and does not change at runtime. Everything works perfectly when I run the game in the Unity Editor, but when I build and run the game on a mobile device, the list contains the correct number of elements but all of them are null.
Here’s the code I’m using to populate the list:
public class EditorWaypointManager : MonoBehaviour
{
public List<WaypointSettings> allWaypoints = new List<WaypointSettings>();
public List<GenericIntersectionSettings> allIntersections = new List<GenericIntersectionSettings>();
public List<TrafficLightsIntersectionSettings> allTrafficLightsIntersection = new List<TrafficLightsIntersectionSettings>();
#if UNITY_EDITOR
[ContextMenu("Add All Waypoints")]
private void AddAllWaypoints()
{
allWaypoints.Clear();
allIntersections.Clear();
allTrafficLightsIntersection.Clear();
allWaypoints = FindObjectsOfType<WaypointSettings>().ToList();
allIntersections = FindObjectsOfType<GenericIntersectionSettings>().ToList();
allTrafficLightsIntersection = FindObjectsOfType<TrafficLightsIntersectionSettings>().ToList();
EditorUtility.SetDirty(this);
}
#endif
}
When I build the game for Android, I log the list, and it shows that there are 8071 elements, but every single element is null.
What could be causing this issue, and how can I fix it so that the waypoints are correctly referenced in the mobile build?