Application.EnterPlayMode takes too long | Assigned Your hefty assignment in Editor Mode | Profile First

  You may get stuck when playing the unity scene? Or is it taking a long time to enter in-play mode in unity3d? Or the workspace or unity player takes a long time to start/play. You are constantly watching Application.EnterPlaymode dialouge.? Then, you have to profile it first. In the below video, you can watch how to check that Where Application.EnterPlaymode has stuck or why it's taking a long time

How to Profile and Check Application.EnterPlayMode Taking time

The profiler will show the reason why is taking more time to load.

A common issue for long player loading time

Now one common issue that your application is take more time to load is due to hefty assignment work in scripting. Like in my situation, I have a script that was attached to 12654 objects and on Awake event,  three objects using FindObjectOfType and GetComponent unity functions were assigned in the variable. This piece of code takes much more time (approx.  6 minutes) on application startup. See my below code snippet


 private void Awake()

    {

        myExcel = FindObjectOfType<MyExcel>();

        objInfoLayringInpPanl = FindObjectOfType<ObjInfoLayringInpPanl>();

        selectedGameObjHasUniqId = GetComponent<GuidComponent>();

    }

For a solution, I simply moved my assignment logic to the editor. On the Custom ContextMenu event, I assigned all the objects on the variable in Editor mode. And my unity workspace/player loading decreased to 15 seconds. From 6+ minutes to 15 seconds loading time. See my below code. The awake block code has moved to a custom function.

  [ContextMenu("Assign Refrences")]

    void AssignRefrences()

    {

        myExcel = FindObjectOfType<MyExcel>();

        objInfoLayringInpPanl = FindObjectOfType<ObjInfoLayringInpPanl>();

        selectedGameObjHasUniqId = GetComponent<GuidComponent>();

    }

Remember It is not necessary that your workspace is loading slowly due to this problem or only a scripting problem. Therefore profile first to determine the reason. Then take action!

Post a Comment

0 Comments