sttz / trimmer

An editor, build and player configuration framework for the Unity game engine.
MIT License
104 stars 8 forks source link

`OnBuildError` is not called if `PrepareBuild` throws an exception #13

Closed JesseTG closed 1 year ago

JesseTG commented 1 year ago

OnBuildError is called if BuildPipeline.BuildPlayer (called within BuildSync) fails. The same cannot be said if PrepareBuild fails.

sttz commented 1 year ago

It seems that's only the case for PrepareBuild? If an option throws an exception in PrepareBuild or the exception on Manager.cs#L474 is hit, OnBuildError won't be called.

But for the native Unity events like OnPreprocessBuild and OnProcessScene, the exception should be reported by Unity as an error in the build report. Or are there cases where Unity allows the exception to reach BuildSync?

It seems the main challenge is that we don't have a BuildReport at that time and cannot create one. So the OnBuildError has to be changed to include an additional error parameter and pass null for the report.

JesseTG commented 1 year ago

I think I made the assumption that OnBuildError wouldn't be reached from the other build phases. PrepareBuild is indeed the only one I've actually observed.

I'll go ahead and send a PR for that suggested change later today.