Optimize Scene Load. Profiler doubt

My team and I are creating a 2,5D Game and we need to optimize scene loading. Does anybody have any tips on how to not stack that many Start operations?

We are currently using Unity 5.3.4f1

Also, playing around with the profiler we don’t understand why the % adds up but the ms don’t add.
How can the line in blue spend less ms than its first child (3669.57 ms vs 6713.08)???

Can you not just have a loading screen, or do you want it to appear a lot quicker for example on mobile I expect they have shorter attention spans.
Im no professional so all I can suggest is, have less stuff in awake/start?
Show us the UnitAI Awake code, it would help greatly.
(Ive seen people say this before so I will say it now, NO, people will not ‘steal’ your code.)

1 Like

We want the transition to be as quick as possible. The game is not oriented to operate on mobile platforms.

We may try to have less stuff in awake/start.

As for the code of the UnitAI, it’s not a matter of code stealing, the code is highly convoluted since it calls other functions and we set each unit type separately.

We called 2.5D but truth is, our game is 3D Game with billboarded sprites Tile Based (hence the SortingOrderInZAllChildren script).

We mainly do 3 operations:

SetMe(meProvisionalEditor);

SceneControl.SetSideUsingUnit(this,unit);

boolresurrect = unit.bMerc && SceneControl.control.MercIsRespawning(unit);
listAlteredState = newList();
if(!resurrect)
{
me=newUnitRTSUnit();
me.rtsUnit=unit;
}
else
{
GetMercebinaryFromRTSUnit(unit);
}

me.goCharacter=this.gameObject;
me.unitAI=this;

if(unit.bMerc && me.iExpAcumulative>0)
{
me.listSkills=me.listSkills;
}

UnitNavMeshAgentunitNavMeshAgent=GetComponent();
if(unitNavMeshAgent==null)
{
//aitype=AIType.Obstacle;
}
elseif(me.rtsUnit.fForm==RTSUnit.Form.Torre)
{
//aitype=AIType.Tower;
//gameObject.layer=10;//Noselepuedeponerlayer 10
}
else
{
unitNavMeshAgent.SetSeekerPenalties(me.rtsUnit);
unitNavMeshAgent.StartHeight(me.rtsUnit.fLevitateHeight);
}

if(iSide>1)
{
bIsInAgro=true;
}

if(me.rtsUnit.fForm==RTSUnit.Form.Torre)
{
InitTower();
}

if(!IsObstacle()&& !IsMuro()&& !IsTower())
{
me.SetUnitSpeed();
}

gameObject.name=me.rtsUnit.sName;
me.InitIngame(gameObject);

//Initialize graphics
if(!IsObstacle()&& !IsMuro())
{
SetUnitWithRTSUnit(me.rtsUnit,me);
}
if(me.rtsUnit.bIntelligentAvoidance)
{
bIntelligentAvoidance=me.rtsUnit.bIntelligentAvoidance;
}

if(unitNavMeshAgent !=null)
{
unitNavMeshAgent.UpdateFacingRightOrLeft();
}

SortingOrderByZAllChildrensorting=GetComponentInChildren();
sorting.Reset();
sorting.UpdateOrderInLayer();

// ChangeColorChilds
if(transform.GetChild(0).GetChild(0).gameObject.GetComponent()==null)
{
transform.GetChild(0).GetChild(0).gameObject.AddComponent();
}

// Alphaslow
if(transform.GetChild(0).gameObject.GetComponent()==null)
{
AlphaSlowalphaslow=transform.GetChild(0).gameObject.AddComponent();
alphaslow.listIgnoreSprite=newList();
alphaslow.listIgnoreSprite.Add(transform.GetChild(0).GetChild(0).gameObject.GetComponent());
if(unitInfo !=null)unitInfo.alphaSlow=alphaslow;
}

//GetComponentInChildren().AdjustColliderPlane();

Billboardbillboard=GetComponentInChildren();
billboard.DoBillboard();

if(CameraRTS.cameraRTS !=null&&CameraRTS.cameraRTS.minimap !=null)imageMinimap=CameraRTS.cameraRTS.minimap.SetMinimapPosition(this,refbRepresentInMinimap);

InitializeUnitInfo();

//Getthe components
unitInfo.unitAI=GetComponent();
unitInfo.unitNavMeshAgent=GetComponent();
unitInfo.unitAttackManager=GetComponent();
unitInfo.unitSpecialSkill=GetComponent();
unitInfo.obstacle=GetComponent();
unitInfo.obstacleClickCollider=GetComponentInChildren();
unitInfo.unitPenalty=GetComponent();

unitInfo.interactiveRadius=GetComponent();

unitInfo.billboard=GetComponentInChildren();
unitInfo.alphaSlow=GetComponentInChildren();
unitInfo.unitAnimations=GetComponentInChildren();

InitializeAIStates();

if(standbyState==null) standbyState=newStandbyState(this);
if(movingState==null) movingState=newMovingState(this);
if(fallingState==null) fallingState=newFallingState(this);
if(movingToAttackState==null) movingToAttackState=newMovingToAttackState(this);
if(movingToDialogue==null) movingToDialogue=newMovingToDialogue(this);
if(movingRestoreState==null) movingRestoreState=newMovingRestoreState(this);
if(movingToSkillState==null) movingToSkillState=newMovingToSkillState(this);
if(attackingState==null) attackingState=newAttackingState(this);
if(doingSpecialSkillState==null) doingSpecialSkillState=newDoingSpecialSkillState(this);
if(deadState==null) deadState=newDeadState(this);

Those are certainly some interesting profiler results, and not just the weird milliseconds. Your Total and Self are both very far over 100%. I’d dare to guess it’s something to do with 50,000 calls and over 12 mb of allocations in one frame. There’s no way that is ever going to be smooth. From the little I’m seeing, your entire architecture needs a lot of work to ever scale properly.

For one, yeah, don’t use Awake and Start so much for general initialization. Use your own methods, and then you have control over when and how they’re called. Then you could spread your initialization calls out over time, or even initialize on a background thread.

2 Likes