Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor freezes more than usual when hitting play. #378

Open
axelbau24 opened this issue Apr 10, 2020 · 96 comments
Open

Editor freezes more than usual when hitting play. #378

axelbau24 opened this issue Apr 10, 2020 · 96 comments

Comments

@axelbau24
Copy link

Please fill in the following fields:

Unity editor version: 2019.3.7f1
Firebase Unity SDK version: 6.13.0
Source you installed the SDK (.unitypackage or Unity Package Manager): .unitypackage
Firebase plugins in use (Auth, Database, etc.): FirebaseMessaging.unitypackage
Additional SDKs you are using (Facebook, AdMob, etc.): None
Platform you are using the Unity editor on (Mac, Windows, or Linux): Windows 10
Platform you are targeting (iOS, Android, and/or desktop): Android
Scripting Runtime (Mono, and/or IL2CPP): Tried both

Please describe the issue here:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

Everytime i hit play (even on a empty project), Unity takes too long to build, compared to the usual time, this is not practical for me.
Also, when the game starts (the play button becomes blue), the editor completely freezes for a few seconds as if it was compiling the game once again.
Am i doing something wrong ?

To easily reproduce this issue:

  • Create a empty 3D project
  • Switch to Android Platform in the build settings
  • Import FirebaseMessaging.unitypackage from Assets -> Import Package
  • After import, a popup shows up to enable Android Auto-Resolution, click "Enable"
  • The Unity Packager Manager Resolver window opens, click "Add selected registries"
  • Wait until all dependencies update.
  • Don't add anything else, and hit "Play"
  • You will notice the editor freezing and taking way too long to build.

This problem happens even if you don't have any base code running.
Also, tried adding the google-services.json, but it doesn't do anything in this case.

Please answer the following, if applicable:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)?
Yes, the exact same thing happens here, and it feels worse.

What's the issue repro rate? (eg 100%, 1/5 etc)
100%

@axelbau24 axelbau24 added the new New issue. label Apr 10, 2020
@patm1987
Copy link

Hi @axelbau24 ,

Thanks for your report!

You've done everything right so far, but I've been unable to replicate the issue on my end. Can you tell me if you see any windows, dialogs, &c pop up after the first time you hit play (screenshot them if you like/can)? Do you see anything interesting in your Console window/would you mind sharing your Editor log?
image

(note that if you don't feel comfortable sharing your Editor log publicly, you can file a bug here and link this issue/say you're trying to add information for this bug).

Is there anything else of interest that you can think of in your setup? Are you using meta files? A version control system other than Git? Is part of your unity project readonly or stored on a synced volume (ex: Dropbox, iCloud, &c)?

I'm checking in with the rest of the team to see if there's anything else we need to verify.

Thanks,
--Patrick

@patm1987 patm1987 added needs-info Need information for the developer and removed new New issue. labels Apr 14, 2020
@almosr
Copy link

almosr commented Apr 15, 2020

I have similar experiences with Firebase Core and Analytics. If I remove them from the project then everything goes back to normal. I doubt that this would make any difference, but I used External Dependency Manager for Unity (EDM4U) and Unity Package Manager to install the packages.

Nothing is synced in the background for my project, it is a fairly straightforward setup. Code generation is set to .NET 4.x and IL2CPP, but changing the setting to Mono makes no difference.

A similar delay also happens when I switch from my code IDE (JetBrains Rider) to Unity editor, if there was any change on the source code and it is recompiled in the background Unity editor stops responding for a good 15-20 seconds.

I have tried profiling the editor to figure out what is going on. I am no expert on Unity profiling, but as it seems to me when this delay happens then profiler stops capturing anything until the editor starts working again.

Please let me know if there was any other information I could provide.

@almosr
Copy link

almosr commented Apr 16, 2020

I have attached the editor log from the moment I press the play button:
editor_log.txt

This line looks rather suspicious to me:

Unloading 534 unused Assets to reduce memory usage. Loaded Objects now: 5522.
Total: 15.606300 ms (FindLiveObjects: 0.836300 ms CreateObjectMapping: 0.170500 ms MarkObjects: 13.140400 ms  DeleteObjects: 1.457900 ms)

Edit: nevermind, I just realised it is msecs. :)

@MateusMP
Copy link

MateusMP commented Apr 17, 2020

I might have the same issue. Looking at the editor profiler, there is at least one entry that seems suspicious to me:
profiler

Note that I'm running on Windows 10. I can't say for sure if that XCodeProjectPatcher is related to firebase, but looking through some results on google it seems to be the case. But this seems to be a specific thing for IOS, so why is it running on my windows environment? It seems to be responsible for at least 4s of startup time.

I'm using Firebase 6.13, auth, database and analytics. And google admob.
Running on SSD.

@daksheshpatel
Copy link

daksheshpatel commented Apr 17, 2020

Exact same issue mentioned by MateusMP. It takes almost 4-5 seconds to enter play mode in the empty project with just Firebase core installed from package manager.

@almosr
Copy link

almosr commented Apr 17, 2020

I am running Unity on Windows too, maybe this is an important piece of information.

@axelbau24
Copy link
Author

axelbau24 commented Apr 18, 2020

Thank you for your answer @patm1987

Here's my Editor Log Editor.log

Also, noticed some iOS stuff happening, even though i'm just compiling for Android, just like @MateusMP did, In my case i don't see anything related to XCode, just the iOS resolver (which i don't think it should be there and also taking a long time to compile.

profilerUnity

Is there any way to disable this iOS resolver?

EDIT: This was a completely empty project stored on my PC, no version control or cloud were used.

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Apr 18, 2020
@GorillaOne
Copy link

GorillaOne commented Apr 21, 2020

I'm having a similar symptom (8 second slowdown right after entering playmode). Platform is set to Android. Same Unity and SDK version as original poster. I have also tried disabling all auto-resolve functions in the package, but this seems to get called no matter what. This is a critical issue.

image

Using Google Analytics for Firebase, Firebase Core, and Firebase Cloud Messaging.

@leni8ec
Copy link

leni8ec commented Apr 22, 2020

I have the same issue.
Freezes at 10-15 seconds on press play button.

Unity 2019.2.21, Firebase 6.12.0 and 6.13.0

@DellaBitta DellaBitta added type: bug and removed needs-attention Need Googler's attention labels Apr 22, 2020
@GorillaOne
Copy link

The majority of this slowdown appears to be due to the Google Play Resolver / External Dependency Manager. When removed, the slowdown goes away. Of course, Firebase won't load so you'll need to add it in again before you build - and this option only works when using the manual install because if you're using Firebase unity packages it will not let you uninstall the EDM because the firebase libraries rely on them.

@godiemp
Copy link

godiemp commented Apr 23, 2020

@GorillaOne How do I remove that? Thanks!

@Hauki
Copy link

Hauki commented Apr 23, 2020

I have the same issue.
Freezes at 10-15 seconds on press play button.

@kirilogan
Copy link

kirilogan commented Apr 24, 2020

I’m having the same issue, but on top of this the editor freezing for 20seconds after each code save. It’s getting unbearable. What would normally take me 2 mins to do, takes 3-4x as long.

I also tried a vanilla build using a brand new project and only adding firebase - same issue.

Anyone else experiencing delays between code changes and then switching over to the editor (even with out play)?

@L4fter
Copy link

L4fter commented Apr 24, 2020

I believe this is the same issue as in firebase/quickstart-unity#644

@kirilogan
Copy link

I believe this is the same issue as in firebase/quickstart-unity#644

I think you are right - I was looking at firebase/quickstart-unity#644 earlier and sounds very similar.

@ideka
Copy link

ideka commented Apr 30, 2020

The issue is still present in 6.14.0, EDM version 1.2.153.

As a workaround for those using the Package Manager versions, you can simply delete the Editor folder and Editor.meta file within Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager. You may have to do it every time you start Unity.

You'll sometimes get an error message about failing to load Firebase.Editor.dll, but it seems you can safely ignore it.

@kirilogan
Copy link

The issue is still present in 6.14.0, EDM version 1.2.153.

As a workaround for those using the Package Manager versions, you can simply delete the Editor folder and Editor.meta file within Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager. You may have to do it every time you start Unity.

You'll sometimes get an error message about failing to load Firebase.Editor.dll, but it seems you can safely ignore it.

The issue is still present in 6.14.0, EDM version 1.2.153.

As a workaround for those using the Package Manager versions, you can simply delete the Editor folder and Editor.meta file within Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager. You may have to do it every time you start Unity.

You'll sometimes get an error message about failing to load Firebase.Editor.dll, but it seems you can safely ignore it

What would be the downside of this? Would it be that you can’t add any new firebase packages or does the dependency manager get re-added (and that’s why we need to remove each time?)

@ideka
Copy link

ideka commented Apr 30, 2020

What would be the downside of this? Would it be that you can’t add any new firebase packages or does the dependency manager get re-added (and that’s why we need to remove each time?)

You lose all firebase editor-specific functionality, but you can restore the folder when you actually need the functionality, and keep it removed when you don't. I assume you need it for building, resolving dependencies, probably for installing or removing packages too.

Obviously not ideal but I think it's a serviceable workaround for now, until this issue is fixed.

@brunoschalch
Copy link

Same issue here!
When I play a scene, music starts to play but all graphics and the unity editor are frozen for a couple of seconds.
I can confirm this happened only after adding Firebase Analytics (Android + iOS) to my project.

Unity 2019.3.10f1, Firebase 6.14.0

@almosr
Copy link

almosr commented May 1, 2020

Deleting this folder: Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager does NOT solve the issue. It is a problem with Firebase and not EDM.

The only workaround I was able to figure out is to remove Firebase from the project while I edit it and put it back when I create a new build.

@ideka
Copy link

ideka commented May 1, 2020

@almosr The workaround I posted definitely solves it for me. Maybe it's two different issues, or our environments are different somehow.

A reminder just in case, Unity restores the folder when you open the project, so you have to delete it when the project is already open.

@almosr
Copy link

almosr commented May 1, 2020

@ideka When I deleted that aforementioned folder while Unity is open then the issue disappears, because Firebase fails to initialize. Unity keeps throwing various errors, I would rather recommend to remove Firebase from the dependencies, that is a cleaner way to workaround the issue.

@chkuang-g chkuang-g self-assigned this Jul 30, 2020
@G-r-i-n-c-h
Copy link

I had to switch to OSX to work on project :D

@chkuang-g
Copy link
Contributor

chkuang-g commented Aug 6, 2020

Hi folks,

We just updated EDM4U to 1.2.157.

The most relevant changes to this thread is that now it will only initialize iOSResolver/AndroidResolver only if the current active build target is iOS/Android and not in play mode. That is, if your current build target is not iOS, iOSResolver initialization will never happen when you click on the Play button. If your current build target is iOS, iOSResolver initialization will happen after you exit the play mode.

At least, it will not try to do the slow searching for UnityEditor.iOS.Extensions.Xcode.dll unless you switch to iOS build target. While the searching is a workaround for a bug in some versions of Unity, this should not bother you now unless you are in that unfortunate version of Unity.

You should be able to get the latest .unitypackage here. UPM version should be available in 20ish min.

However, I can still see a couple of performance improvement for both EDM4U and Firebase SDK.

  1. [Firebase] Search for google-services.json and/or GoogleServices.plist
  2. [EDM4U] Search for Dependencies.xml

These searches use standard AssetDatabase.FindAsset(). Since we do not require the user to label them or put them in a fixed folder, the code basically need to use a generic search across the whole Asset Database. And our editor plugins require at least load them once to handle any upcoming events, such as post process event and build request.

The tricky thing is AppDomain reloads whenever play mode starts (there is a flag introduced in later version of Unity which prevent this. I feel very skeptical about it.)

Still looking into some solutions. And feel free to make some suggestoins.

I'll keep this thread open until we have a better solution for the searching.

Shawn

@jimanjr
Copy link

jimanjr commented Aug 7, 2020

Did anyone profile AssetDatabase.FindAsset()? I don't think it's an issue performance-wise, but if it is you can probably cache its path in EditorPrefs after the first FindAsset?

@chkuang-g
Copy link
Contributor

I think it will be slower when the Unity project grows.

Caching is tricky since those files can be added anytime with or without Unity is opened.

Well, only if there is something that can be called only ONCE after the Unity is launched.

The closest thing I get so far is using [InitializeOnLoad], static constructor and EditorApplication.isPlayingOrWillChangePlaymode, which might be good enough. :/

@chkuang-g
Copy link
Contributor

BTW, some improvement from the Firebase SDK will be included in the next release.

@JoNax97
Copy link

JoNax97 commented Aug 13, 2020

Hello!
Thank you for working on improving the performance of the plugin! In the meantime, I think you can allow disabling the automatic checking (but have it enabled by default as to not alter the current behaviour) for those users who don’t need it all the time. Additionally, you can expose the method through the menu to allow manual checking.
Here's a working sample that creates a menu entry that can be toggled on/off and saves its state to the EditorPrefs:

    [InitializeOnLoad]
    public static class AutomaticCheckingSetting
    {
        private const string MENU_NAME = "Window/Firebase/Check Configuration Automatically";
        private const string PREF_NAME = "firebase_check_config_automatically";

        public static bool Enabled
        {
            get { return EditorPrefs.GetBool(PREF_NAME, true); } // Return true if the pref is not set
            set
            {
                EditorPrefs.SetBool(PREF_NAME, value);  // Saving editor state
            }
        }
        
        // Called on load thanks to the InitializeOnLoad attribute
        static AutomaticCheckingSetting() {

            // Delaying until first editor tick so that the menu
            // will be populated before setting check state, and
            // re-apply correct action
            EditorApplication.delayCall += () => Menu.SetChecked(MENU_NAME, Enabled); // Set checkmark on menu item
        }
     
        [MenuItem(MENU_NAME)]
        private static void ToggleSetting()
        {
            Enabled = !Enabled;
            Menu.SetChecked(MENU_NAME, Enabled);
        }
    }

And here’s how the current code would use it:

[InitializeOnLoad]
public class GenerateXmlFromGoogleServicesJson
{
    static GenerateXmlFromGoogleServicesJson()
    {
        if (!EditorApplication.isPlayingOrWillChangePlaymode && AutomaticCheckingSetting.Enabled)
        {
            RunOnMainThread.Run(delegate
            { 
                GenerateXmlFromGoogleServicesJson.CheckConfiguration();
            }, false);
        }
    }
    
    [MenuItem("Window/Firebase/Check Configuration Now")]
    public static void CheckConfiguration()
    {
       // Check configuration logic
    }
}

@sanuzzi
Copy link

sanuzzi commented Aug 13, 2020

☝️ Good proposal @JoNax97 ☝️
That would be very useful! So we stop wasting so much time!

@josefalanga
Copy link

Indeed, checking the configuration is very useful, but It's not necessary on every recompile. Having a toogle to opt-out and a manual check option sounds awesome. @JoNax97's proposal looks great!

@guidoPaglie
Copy link

@JoNax97 excellent proposal, we are having the same problem.

@JoNax97
Copy link

JoNax97 commented Aug 21, 2020

@chkuang-g Have you had time to check the code I posted? :)

@chkuang-g
Copy link
Contributor

@JoNax97

This is great proposal. Thanks for sharing.
The team is working on other issues at the moment.
Will keep you posted.

@InfinitiesLoop
Copy link

This issue manifested in another way for me. It completely killed my ability to build the game. Due to a separate issue, our build generates a bunch of assets, and it does so by writing them to a folder that is inside the Assets directory. This was causing there to be a refresh in Unity after every file. Thousands of files were being written, so we were incurring this added delay thousands of times. Builds would go for 5 hours before being killed off, and probably would take days if left running. We sort of fixed the original problem by pausing refreshes with StartAssetEditing() and StopAssetEditing() calls before/after the asset generation, and that has alleviated the problem, but there are other aspects of our build that are outside of that, so still incurring overhead from the Firebase issue.

@ZLTM
Copy link

ZLTM commented May 11, 2021

after adding a real-time database script I cant use the play button anymore, I tracked the problem to this code

void Start()
    {
        DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
    }

Of course, we need this to be able to push and pull values from the DB, anyone found any solution?

@ORibn-dev
Copy link

I have similar kind of issue on Unity 2019.4.16f1, Editor permanently freezes after 2nd/3rd Play or 2nd/3rd code compiling in Visual Studio, so I have to restart Unity every time. I have Firebase Database, Storage and Remote Config. I didn't have this issue before, even though I had freezes from time to time, but now I have this problem and don't quite understand where it came from.

@MBRSL
Copy link

MBRSL commented Jan 18, 2022

@chkuang-g
It's been years. Is there any news of this issue? GenerateXmlFromGoogleServicesJson not only slow down editor performance, it also produce lots spam in Unity editor logs. This causes so much troubles when debugging CI pipeline.

@mrKrenar
Copy link

mrKrenar commented Mar 1, 2022

Guys, come on! Is there any update yet on the issue? I am having serious troubles for some times now, can't work for more than 5 minutes in same project without needing to force kill unity!

@cynthiajoan cynthiajoan transferred this issue from firebase/quickstart-unity Jun 24, 2022
@binouze
Copy link

binouze commented Nov 30, 2022

Hi,
Still no news about this issue ?
Why don't you just run your GenerateXmlFromGoogleServicesJson code in a pre build process instead of at every compilation ?
Is this xml useful in editor ?

@kakkou
Copy link

kakkou commented Jan 26, 2023

I was having the same problem but found out that the cause is the anti-virus protection.
It slows down the initial launch of generate_xml_from_google_services_json.exe, which is created by Pyinstaller.
When the protection status is enabled, it takes 10 seconds to get an error code when run directly at the command prompt.
Registering the exe in the exclusion settings improved the situation.

@VanIseghemThomas
Copy link

Still a problem on Windows in 2023, any updates?
Seems that it's caused by Firebase.Editor.XcodeProjectPatcher:CheckBuildEnvironment

@tomkail
Copy link

tomkail commented Sep 25, 2023

Stumbled on this thread while trying to improve editor performance. Adding our voice here - this is a serious issue that doubles the time it takes for Unity to recompile for us. We started using Firebase last month but we're going to have to abandon it due to this issue.

@VanIseghemThomas
Copy link

@tomkail we ditched the Firebase SDK and I just wrote our own implementation using the REST API endpoints. For us we just needed auth and the existing NuGet package for auth was giving us problems on certain versions of Unity.

@novi-ranoja
Copy link

novi-ranoja commented Nov 17, 2023

image

Any fixes? still an issue as of now, unity version: 2021.3.2f1, iOS Target Build in Unity Windows Platform

after integrating the firebase messaging plugin, tried it with our current 10.6.0 firebase version with external dependency version of 1.2.175 & also updated it to 11.6.0 version with external dependency version of 1.2.177 still the same freezing on playmode.

@tomkail
Copy link

tomkail commented Nov 17, 2023 via email

@mrKrenar
Copy link

@novi-ranoja editor freezing is generally a problem related to unity 2021, in my experience. Maybe you can try to upgrade to 2022

@MuhammadBasitUnityDev
Copy link

MuhammadBasitUnityDev commented Nov 7, 2024

Screenshot 2024-11-07 at 11 37 04 AM

We are facing performance Hit on splash screen while it's initialization on Android & iOS. It's something related to firebase.platforms.dll it's taking about 3000 to 4000 mili seconds to load and App gets freeze in this time. I am using the recommended way for initialization. I did tried ContinueWith rather using ContinueWIthOnMainThread but it didn't either fixed the issue.
My Unity version is 2022.3.36f1 & My firebase sdk version is 12.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests