Unity-Technologies / EntityComponentSystemSamples

Other
7.23k stars 1.62k forks source link

Boids - Errors on player build #237

Open PitouGames opened 1 year ago

PitouGames commented 1 year ago

I have errors when building the boids project for Windows. I'm using Unity 2022.2.1f1 and made no script modification. Juste open the projet, add the "Boids" scene to build settings and build.

Errors:

Assets\Scripts\Systems\BoidSchoolSpawnSystem.cs(13,5): error SGICE002: This error indicates a bug in the DOTS source generators. Assets\Scripts\Systems\BoidSchoolSpawnSystem.cs(13,5): error SGICE002: This error indicates a bug in the DOTS source generators. We'd appreciate a bug report (Help -> Report a Bug...). Thanks! Error message: 'System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.) |--| ---> System.NullReferenceException: Object reference not set to an instance of an object. |--| at Unity.Entities.SourceGen.Common.SymbolExtensions.ToFullName(ITypeSymbol symbol) |--| at Unity.Entities.SourceGen.SystemAPIQueryBuilder.SystemAPIQueryBuilderDescription.<>c.<.ctor>b__18_1(Query t) |--| at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext() |--| at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext() |--| at System.String.Join(String separator, IEnumerable`1 values) |--| at Unity.Entities.SourceGen.Common.EnumerableHelpers.SeparateByCommaAndSpace(IEnumerable`1 lines) |--| at Unity.Entities.SourceGen.SystemAPIQueryBuilder.SystemAPIQueryBuilderDescription..ctor(SystemDescription systemDescription, QueryCandidate queryCandidate) |--| at Unity.Entities.SourceGen.SystemAPIQueryBuilder.SystemAPIQueryBuilderModule.RegisterChangesInSystem(SystemDescription systemDescription) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemGenerator.<>c__DisplayClass2_1.b__1(SyntaxTree syntaxTree) |--| at System.Threading.Tasks.Parallel.<>c__DisplayClass44_0`2.b__1(IEnumerator& partitionState, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) |--| --- End of stack trace from previous location --- |--| at System.Threading.Tasks.Parallel.<>c__DisplayClass44_0`2.b__1(IEnumerator& partitionState, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) |--| at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion) |--| at System.Threading.Tasks.TaskReplicator.Replica.Execute() |--| --- End of inner exception stack trace --- |--| at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure) |--| at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) |--| --- End of stack trace from previous location --- |--| at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException) |--| at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) |--| at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) |--| at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body) |--| at Unity.Entities.SourceGen.SystemGenerator.SystemGenerator.Execute(GeneratorExecutionContext context)'

image

Playing in the editor has no problem.

Forerunner2012 commented 1 year ago

Hello. The #if UNITY_EDITOR ... #endif is being too all-encompassing in the Authoring scripts causing the build issue. To solve it, limit the scope to only the BoidAuthoring, BoidObstacleAuthoring, BoidSchoolAuthoring, BoidTargetAuthoringand TransformRecorderAuthoringor extract the struct in a dedicated C# file.

In addition, I found it particularly intriguing to put the structure after its authoring.

Forerunner2012 commented 1 year ago

Here is a patch for a temporary fix. You can apply it within your project using git apply BuildBoids.patch. Note that I have switched the structure to be on top for more personal clarity. BuildBoids.patch