0

I have a two scenes: Menu and Main. And I have a huge lag on SceneManager.LoadScene("Main").

Here is a data from profiler: https://gyazo.com/da116d1f8e9b429e9170bc3769d23ac4

As I understand 1s delay related to initializing Zenject context.

Here is my installer:

using LevelGenerators;
using Signals;
using States;
using UnityEngine;
using Zenject;

public class MainMonoInstaller : MonoInstaller<MainMonoInstaller>
{
    [Inject] public BrickController.Settings BrickSettings;

    public override void InstallBindings()
    {
        Container.BindInterfacesAndSelfTo<GameController>().AsSingle().NonLazy();
        Container.BindInterfacesAndSelfTo<ScoreboardDataController>().AsSingle();
        Container.BindInterfacesAndSelfTo<InputController>().AsSingle();
        // signals
        Container.DeclareSignal<LaunchBallSignal>();
        Container.DeclareSignal<GameStateChangedSignal>();
        Container.DeclareSignal<MovePlayerSignal>();
        Container.DeclareSignal<MovePlayerToPositionSignal>();
        Container.DeclareSignal<FloorTouchedSignal>();
        Container.DeclareSignal<GiveScorepointsSignal>();
        Container.DeclareSignal<AttachToPlayerSignal>();
        Container.DeclareSignal<LevelCompletedSignal>();
        Container.DeclareSignal<ResetPlayerStateSignal>();
        Container.DeclareSignal<GameEndedSignal>();
        // factories
        Container.Bind<StateFactory>().AsSingle();
        Container.BindFactory<StartingGameState, StartingGameState.Factory>();
        Container.BindFactory<PlayingState, PlayingState.Factory>();
        Container.BindFactory<GameOverState, GameOverState.Factory>();

        Container.BindFactory<ClassicLevelGenerator, ClassicLevelGenerator.Factory>();
        Container.BindFactory<StarLevelGenerator, StarLevelGenerator.Factory>();
        //
        Container.BindFactory<BrickController, BrickController.Factory>()
                 .FromComponentInNewPrefab(BrickSettings.BrickPrefab)
                 .WithGameObjectName("Brick");
        Container.BindInterfacesAndSelfTo<LevelManager>().AsSingle();
        Container.Bind<LevelGeneratorFactory>().AsSingle();
    }
}

The scene has about 40 gameobjects at runtime.

I am using Unity 2017.2.1f1, .NET 4.6 and Zenject 5.5.1.

Are there a ways to speed up switching between scenes?

Crabar
  • 1,829
  • 1
  • 14
  • 26
  • 335 ms for SceneContext.Resolve seems high for such a simple installer, and only 40 game objects. Are you doing any work inside an [Inject] method or constructor that could help explain the lag? You could try the preview version of zenject (develop branch on github repo) to see if that help, since there were a bunch of optimizations added to the Resolve method there – Steve Vermeulen Apr 11 '18 at 12:16
  • No, I didn't do anything huge in inject methods, just setting properties. I'll try preview version, maybe it helps. BTW, here is my repository https://github.com/Crabar/Craberoid-3.0. Game is not big, so if you have time and passion I will appreciate your help. – Crabar Apr 12 '18 at 12:20

0 Answers0