playMaker

Author Topic: Black Screen after Unity Splash for a few seconds[SOLVED]  (Read 4802 times)

ucanonel

  • Playmaker Newbie
  • *
  • Posts: 4
Black Screen after Unity Splash for a few seconds[SOLVED]
« on: November 12, 2019, 12:42:22 AM »
I've been struggling for a while because I've got a black screen after unity splash for 7 seconds on both Android and iPhone devices in my project.(Samsung Note9 and iPhone 6s) Then I tried everything to solve it but I couldn't. I deleted all assets that would cause the problem but it didn't work. Finally, I created a new empty scene and try to add some FSMs to it. After 40-50 FSMs it becomes happening. If the FSM amount increases at the start scene, the black screen time increases. Is it normal? It wasn't happening in the other projects of mine.

I'm using Playmaker 1.9.0 p19 and Unity 2019.2.11f1.

« Last Edit: November 14, 2019, 01:33:01 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Black Screen after Unity Splash for a few seconds
« Reply #1 on: November 12, 2019, 12:47:29 AM »
Hi,

 it's not the fsm that is making Unity stall, it's what you do in these fsm. Can you tell us what actions you are using? it's likely that you either have some loops that are too heavy, or are using some actions that are too expensive to run this way ( like findGameObject)

or are you saying these 50 fsm are actually empty and do nothing?!

 Use the profiler, if you get that much delay on mobile, you should also witness that in editor, right?


Bye,

 Jean

ucanonel

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Black Screen after Unity Splash for a few seconds
« Reply #2 on: November 12, 2019, 02:03:45 AM »
Hi Jean,

Yes, I have a problem with the editor as well. I don't have any black screen but the game starting time after pressing play is really long in the editor as well.

Actually, there are some managers (game, UI, sound, etc.)that sets and gets variables, activating objects and creating prefabs onto the scene. Game manager mostly set the variables and send events to the gameobjects and the other managers. UI manager creates and activates UI objects(Buttons, TextMesh Pro Texts) on Canvas and they have also FSMs including mostly tween animations. I don't think the actions cause the problem. There are no loops or complex actions at the start events.

Is there anywhere I can find out about performance or optimization on Playmaker?

I attached the profiler at the start, I don't know what it means.

PS: I've just tried to deactivate all things on my scene, and it still gives me 7seconds black screen. Does the Playmaker FSMs work in the background even the object is deactivated, or what can it be? When I created an empty scene, it didn't give any black screen.

EDIT: Is it possible to have too many global variables causing it? More than 30 global variables.
« Last Edit: November 12, 2019, 08:26:49 AM by ucanonel »

ucanonel

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Black Screen after Unity Splash for a few seconds
« Reply #3 on: November 12, 2019, 10:33:44 PM »
Ok, I think I found the problem but I don't know how to solve it.

I have a level manager which looks at the level number and creates the level (a prefab that includes various prefabs) according to the level number. When I tried to add only 1 level in FSM, the game works perfectly. But if I try to look at the level number and create level according to that, the game opens too late.

I made the level selection with int switch. Is this the wrong thing I've done or is something wrong with the prefabs?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Black Screen after Unity Splash for a few seconds
« Reply #4 on: November 13, 2019, 12:51:07 AM »
Hi,

Owww... :) your approach is indeed not optimal at all.

an Fsm state with more than 3 4, max 10 transition is a sign that things should be redesigned.

 in your case, you should use Resources and load stuff by name, where the name was constructed using logic. like :"level"+levelnumberint

it's still not clear to me what's taking time to load, is it the prefab that is too heavy to load, or is it the logic that ends up loading the prefab that has issues?

Bye,

 Jean

ucanonel

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Black Screen after Unity Splash for a few seconds
« Reply #5 on: November 13, 2019, 04:15:30 PM »
Hi Jean,

I moved all of my level prefabs to the Resources folder and I used Resource load instead of creating gameobject action, and it's fixed! I didn't change the logic, the FSM is still messy :) But resource folder worked.

I think when you connect the prefabs into the FSM, the FSM makes all of it ready even if you don't need to use it?

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Black Screen after Unity Splash for a few seconds
« Reply #6 on: November 14, 2019, 01:32:42 AM »
Hi,

not sure what exactly you were doing, but indeed, it looks like you were loading all these prefabs at once.

Bye,

 Jean

Christoph

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 79
Re: Black Screen after Unity Splash for a few seconds[SOLVED]
« Reply #7 on: April 23, 2021, 04:48:42 PM »
Hi! I have exactly the same issue and same situation. Black loading screen after splash and I'm using prefabs for my level sections. On Android it can go all the way up to 40+ seconds. Terrible loading time.

I just reduced the options to those prefabs after 1 week of research and now I come across this thread. I was already looking at the possibility to put the prefabs in resource folder or making asset bundles, but I don't know how to really build that.

Any help is appreciated because it drives me insane.

I do pool those prefabs btw with PoolBoss.

So should I:
1. put the prefabs in the resource folder (now they shouldn't be loaded anymore at awake by playmaker, right?
2. use Resources.LoadAll(“folderNameInsideResources”) to load them at start
3. initialize PoolBoss so the prefabs are instantiated

or do I miss something?

Christoph

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 79
Re: Black Screen after Unity Splash for a few seconds
« Reply #8 on: April 25, 2021, 12:43:32 AM »
in your case, you should use Resources and load stuff by name, where the name was constructed using logic. like :"level"+levelnumberint
What’s the logic of prefabs in resources folder related to Playmaker?

I have literally the exact same situation like the OP. It almost is scary how much alike my situation is. But there’s one difference it seems: if I put an empty scene as my first scene to load a logo or loading bar, the black screen does NOT go away.

Not sure if something changed with how the prefabs are managed by playmaker since there were many updates related to prefabs recently. But at this moment I highly doubt that the resources folder will fix my problem. Will keep trying tomorrow.

I moved all of my level prefabs to the Resources folder and I used Resource load instead of creating gameobject action, and it's fixed! I didn't change the logic, the FSM is still messy :) But resource folder worked.
I know this is an old thread and seems you haven’t been active since then but did this really fix it for good? Would appreciate any help to solve this too.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Black Screen after Unity Splash for a few seconds[SOLVED]
« Reply #9 on: April 30, 2021, 01:36:40 AM »
Hi,

 Resources will help loading time in all cases. I strongly advice to use them as much as you can.

if Unity has to serialize everything that you use inside a scene, the loading time of the scene will increase, because it has to process everything that's in the scene before starting rendering it.

if you move all content that you don't need when you open the scene in resources, or other scenes you load after, these resources/scenes will not take any time during the loading of the app, they will sit in the hard disk inside the application files until your code ( c# of playmaker, it makes no difference here) explicitly wants a particular resources/scene, then unity will take the time to load it before making it available to you for instantiation and rendering.

 Having said that, the only way to know for sure what's happening, is to use the editor profiler and regular profiler and check what is happening during this initial time, where are the spikes, is it sound decompression ( a likely problem), is it scene assets, is it shaders for these new messy rendering pipelines, is it meshes decompression, is it texture decompression.

Now, as far as playmaker fsm loading time, again, it's what is inside the playmaker fsm that matters, playmaker is just a regular component, so adding tons of playmaker fsm in your scene doesn't necessarly means loading time increase, but if each of your fsm start doing some taxing actions on start, then yes, it will, but the problem woudl be the same if you were using just c#.

Can you run the profiler and let us know what's happening during this black screen?

Also have you checked the player logs on the android when you publish? that's important, maybe something is happening that you are unaware of ( it happens a lot...)

Bye,

 Jean

Christoph

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 79
Re: Black Screen after Unity Splash for a few seconds[SOLVED]
« Reply #10 on: April 30, 2021, 09:52:17 AM »
Hi Jean,

thanks for taking the time to reply.

I did actually change to Resources and it indeed did reduce the black screen a bit and I'm able now to show the first scene or the main scene's UI at around 50% of the complete loading time. That is on the worst device I have available to test on. On other more powerful devices the black screen takes up more percentage in time but overall it loads as well much faster so it's not as much of an issue there.

But I do think it's important to point out that the overall loading time didn't improve. I'm just able to show much quicker the first scene's UI (which is nice for showing a Loading screen).

On my low end Android test device, that black screen still makes up about 5-6 seconds. So I have now 4 seconds Splash screen, then 5-6 seconds black screen, then another 8 seconds showing the UI loading screen.

Note: this is with Resources.LoadAll action without instantiating the prefabs at start up. I'm now in the process of using instead Resources.LoadAsync but this has quickly become a headache in terms of logic because all is based on string arrays that need to be done manually and is extremely prone to error. I wished there is an editor script that can list the prefabs inside a Playmaker array automatically.

When I use a separate scene to show the loading screen it actually takes about 2 seconds more to open the entire game. I guess it has to do with the change of scene.

Also, I have almost no logic in the Start States. There are some variable setups that I found easier to do in a dedicated SETUP state at Start (like color variables) or I enable the Loading Screen canvas, but otherwise not much going on there.

I then use a Core Manager to organize the flow of loading and preparing all needed things in my game and only move on if X task is completed. Like I load first the resources of the current level, and only if those are finished loading, I move on to create the level. But as said above, this part is rather working great and is pretty fast.

What I can't get rid of is that black screen and can't understand how other games are able to show their first scene's UI immediately.

I also did couple of days ago several tests to measure the loading time. All those tests only had a Canvas in the project. Here's the finding:

Clean Unity Project = 4:07 seconds loading time / Black Screen 0:20 seconds
With Playmaker = 4:13 seconds loading time / Black Screen 0:20 seconds
With 100FSM = 5:03 seconds loading time / Black Screen 1:09 seconds

So by adding FSMs the black screen actually already increased by 100%.

I didn't take the tests further because I didn't had the time but I guess if I added logic to those FSMs it would further increase?

Regarding the profilers, in editor profiler as far as I know, it doesn't show what happens before the scene loads (it's just empty at that point). When the scene does load though I do have a huge spike. But I guess this is normal since all FSMs Start methods are firing at the same time? There's also some editor stuff spiking hard so I never really understood how to read it.

I did had some Android logcats but I already deleted them again. Again, I didn't really understand how to read them. I did the same as well in Xcode Profiler, but couldn't read it either...

Edit: and I don't have any sound in my project yet. So sound files are a non issue here.

Mupp

  • Full Member
  • ***
  • Posts: 160
Re: Black Screen after Unity Splash for a few seconds[SOLVED]
« Reply #11 on: April 30, 2021, 10:02:50 AM »
Resources will help loading time in all cases. I strongly advice to use them as much as you can.

Um are you sure?

This is what Unity says:
Quote
2.1. Best Practices for the Resources System
Don't use it.

This strong recommendation is made for several reasons:

    Use of the Resources folder makes fine-grained memory management more difficult.
    Improper use of Resources folders will increase application startup time and the length of builds.
        As the number of Resources folders increases, management of the Assets within those folders becomes very difficult.
    The Resources system degrades a project's ability to deliver custom content to specific platforms and eliminates the possibility of incremental content upgrades.
        AssetBundle Variants are Unity's primary tool for adjusting content on a per-device basis.

2.2. Proper uses of the Resources system
There are two specific use cases where the Resources system can be helpful without impeding good development practices:

    Resources is an excellent system for during rapid prototyping and experimentation because it is simple and easy to use. However, when a project moves into full production, it is strongly recommended to eliminate uses of the Resources folder.

    The Resources folder is also useful in trivial cases, when all of the following conditions are met:

    The content stored in the Resources folder is not memory-intense
    The content is generally required throughout a project's lifetime
    The content rarely requires patching
    The content does not vary across platforms or devices.

Examples of this second case include a globally-used prefab hosting singleton MonoBehaviours or an Asset hosting third-party configuration data, such as a Facebook App ID.

Christoph

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 79
Re: Black Screen after Unity Splash for a few seconds[SOLVED]
« Reply #12 on: April 30, 2021, 04:44:10 PM »
Yeah but Unity says this because if you start to put everything in Resources folders you will have huge build size and if you then use Resources.LoadAll, you will increase your loading times of course.

Plus there was for a long time AssetBundles as a better alternative and now even better Addressables.

But tbh, both, AssetBundles and Addressables is overkill for my needs, so resources works pretty good besides that problem of not being able to pull those paths automatically.

Either way, that black screen is appearing with or without Resources folder.  :o

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Black Screen after Unity Splash for a few seconds[SOLVED]
« Reply #13 on: May 07, 2021, 11:35:37 AM »
Hi,

 yep, I am 100% sure.


"improper use" is for example loading all resources like you do. that's not the way it's intended to be used, you should load resources when you need it before a new leevel or as your gameplay progresses, so that loading is granular with as little as necessary for the task at end.

you seems to mention you use " Resources.LoadAll " that's definitly a big no if you have lots of resources, and you seem to have lots.

Have you ran the profiler? it's very important ( mandatory actually) that you do that at this point, because you may find, it's a sound asset that is compressed and takes up all your loading time, or something along that.

Bye,

 Jean


Resources will help loading time in all cases. I strongly advice to use them as much as you can.

Um are you sure?

This is what Unity says:
Quote
2.1. Best Practices for the Resources System
Don't use it.

This strong recommendation is made for several reasons:

    Use of the Resources folder makes fine-grained memory management more difficult.
    Improper use of Resources folders will increase application startup time and the length of builds.
        As the number of Resources folders increases, management of the Assets within those folders becomes very difficult.
    The Resources system degrades a project's ability to deliver custom content to specific platforms and eliminates the possibility of incremental content upgrades.
        AssetBundle Variants are Unity's primary tool for adjusting content on a per-device basis.

2.2. Proper uses of the Resources system
There are two specific use cases where the Resources system can be helpful without impeding good development practices:

    Resources is an excellent system for during rapid prototyping and experimentation because it is simple and easy to use. However, when a project moves into full production, it is strongly recommended to eliminate uses of the Resources folder.

    The Resources folder is also useful in trivial cases, when all of the following conditions are met:

    The content stored in the Resources folder is not memory-intense
    The content is generally required throughout a project's lifetime
    The content rarely requires patching
    The content does not vary across platforms or devices.

Examples of this second case include a globally-used prefab hosting singleton MonoBehaviours or an Asset hosting third-party configuration data, such as a Facebook App ID.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Black Screen after Unity Splash for a few seconds[SOLVED]
« Reply #14 on: May 07, 2021, 11:43:54 AM »
Hi,

you should not use Resources.LoadAll, that methos is here for debugging where you can get it all and check, but really, you should do that at all in a normal game logic.

you must know your resources, your logic has to maintain a naming convention for example, where your resources are named in a way that you can get to them without harcoded their path in your logic or data, that's not how it works best.

 you maintain Ids of your weapons or resources items, these Ids are not the names you show to your players, they are internal ids, and when a player select weapon X, you build the resources path string like "/weapon/Xid" . That's how it works best and most effectivly.

asset bundles and addressables are not going to solve your scene loading problems ( unless your problem is simply that you load all resources in one go at start....) .

your scene as some assets in it, that's what unity has to deserialize first, anything elsee doesn't impact the scene loading, not resources, no asset bundles, not addressables.

Please run the profiler and check memory usage, and code execution, spot the spikes at the scene loading time and dig deep into exactly what cause this spike.

 Let me know your findings, it could be anything really... either way too much assets, and that will call for splitting up your scene to load them additivly on the go, or some assets needs optimization.

 Also, you should also load your scene asynchronously, and disply a progress bar, you will see how much time it taken to load the scene in memory, and then how much time it takes unity to deserialze this memory chunck .

 Can you tell me the size in Mb of the you load in your asset folder?

Bye,

 Jean

Yeah but Unity says this because if you start to put everything in Resources folders you will have huge build size and if you then use Resources.LoadAll, you will increase your loading times of course.

Plus there was for a long time AssetBundles as a better alternative and now even better Addressables.

But tbh, both, AssetBundles and Addressables is overkill for my needs, so resources works pretty good besides that problem of not being able to pull those paths automatically.

Either way, that black screen is appearing with or without Resources folder.  :o