Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Something went wrong when PostProcessing the assembly, from Entities.Foreach lambda

Discussion in 'Entity Component System' started by Sarkahn, Dec 4, 2019.

  1. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Hello. I got this unfriendly error:
    Code (CSharp):
    1. Something went wrong while Post Processing the assembly (Assembly-CSharp.dll) :
    2. Sequence contains no matching element
    3.   at System.Linq.Enumerable.Single[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x00070]
    From this:
    Code (CSharp):
    1.  
    2.  
    3.       var bufferEntity = streamBufferQuery.GetSingletonEntity();
    4.       var bufferFromEntity = GetBufferFromEntity<SpriteUVData>(false);
    5.  
    6.       inputDeps = Entities.
    7.             WithNone<StreamBuffer>().
    8.             WithChangeFilter<SpriteUVData>().
    9.             WithNativeDisableParallelForRestriction(bufferFromEntity).
    10.             ForEach(
    11.             (int entityInQueryIndex, in DynamicBuffer<SpriteUVData> uv) =>
    12.             {
    13.             }).Schedule(inputDeps);
    That's with the empty lambda. It goes away if I comment out the WithNativeDisableParallelForRestriction.

    I'm guessing maybe it's from trying to pass a BufferFromEntity<SpriteUVData> in WithNativeDisableParallelFor while also using DynamicBuffer<SpriteUVData> as a type in the arguments in the lambda?

    For a little more context, these are for two separate entities that have the same type of Dynamic Buffer, I want to copy all the data from all the individual buffers into one big one (without actually making a copy - to avoid the GC allocations).
     
    Last edited: Dec 4, 2019
  2. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    I'm dumb, I guess I wasn't paying attention to the "Sequence contains no matching element" part. The error occurred specifically because i had commented out the code that was using the buffer inside the lambda while I was testing. I still feel like that error message could be a bit clearer about what was wrong there, if at all possible.
     
  3. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    85
    Hey @Sarkahn. Glad you figured out the issue causing the error. This error message is indeed not great. We will replace it with something that gives a better idea of what the real problem is. Thank you for bringing this up.
     
  4. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    198
    i ran into same problem when i try to use generic types in lambda function, will generics be supported ?
     
  5. Lucas-Meijer

    Lucas-Meijer

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    175
    I don't expect us to support generic types used as lambda parameters, or as arguments to .WithAll<> and friends any time soon. A lot of our compiler smarts depends on being able to know which type you are using. You could still share much of the actual iteration code by extracting the lambda method to a static method, and using that from two different Entities.ForEach. If you have particular usecase that is very hard or very inconvenient to achieve without a generic argument, we'd love to learn more about it to better understand the problem.
     
  6. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    198
    n
    thx for reply, not that hard though for my case.
    an off-topic question, how can visual studio/other ide produce same compile error? my frustration mainly came from after i finish my coding, i start to know Enitities doesn't support generics in jobs (meanwhile it does support generics in non-job code)
     
  7. Lucas-Meijer

    Lucas-Meijer

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    175
    It depends on the IDE and its settings how it compiles the code. I'm not sure which IDE's currently do which thing by default, but if they relay the compilatino request to unity, and show unity's output then you get the error when you build in the IDE. if they use a builtin msbuild to compile, you only get the c# specific errors (none in this case), and not the dots compiler errors.
     
  8. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    But my error message is:
    Code (CSharp):
    1. Something went wrong while Post Processing the assembly (Assembly-CSharp.dll) :
    2. Object reference not set to an instance of an object
    3.   at Unity.Entities.CodeGen.TypeDefinitionExtensions.IsComponentSystem (Mono.Cecil.TypeDefinition arg) [0x00001] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\CecilExtensionMethods.cs:142
    4.   at Unity.Entities.CodeGen.TypeDefinitionExtensions.IsComponentSystem (Mono.Cecil.TypeDefinition arg) [0x000a2] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\CecilExtensionMethods.cs:156
    5.   at Unity.Entities.CodeGen.TypeDefinitionExtensions.IsComponentSystem (Mono.Cecil.TypeDefinition arg) [0x000a2] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\CecilExtensionMethods.cs:156
    6.   at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].ToArray () [0x0001d] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
    7.   at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
    8.   at Unity.Entities.CodeGen.LambdaJobsPostProcessor.PostProcessImpl () [0x00001] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\LambdaJobs\LambdaJobsPostProcessor.cs:177
    9.   at Unity.Entities.CodeGen.EntitiesILPostProcessor.PostProcess (Mono.Cecil.AssemblyDefinition assemblyDefinition, System.Boolean& madeAChange) [0x00009] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\EntitiesILPostProcessor.cs:209
    10.   at Unity.Entities.CodeGen.EntitiesILPostProcessors.Process (Unity.CompilationPipeline.Common.ILPostProcessing.ICompiledAssembly compiledAssembly) [0x0004b] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\EntitiesILPostProcessor.cs:44
    11.   at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.RunILPostProcessors (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.String outputTempPath) [0x0011b] in <3b74787e58694cdda2c241162159b3b7>:0
    12.   at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.PostProcess (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.Collections.Generic.List`1[T] messages, System.String outputTempPath) [0x00061] in <3b74787e58694cdda2c241162159b3b7>:0
    What's it mean??
     
  9. Lucas-Meijer

    Lucas-Meijer

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    175
    This is a bug. Well improve the error message. Are you able to share this project folder with us?
     
  10. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    My Project is too large that i can't share to you.
    If I modify Unity.Entities.CodeGen.CecilExtensionMethods.cs:
    upload_2019-12-12_10-58-48.png

    The log is:
    upload_2019-12-12_11-0-28.png
    Is it helpful?
     
  11. Roycon

    Roycon

    Joined:
    Jul 10, 2012
    Posts:
    50
    I too have run into this bug, my horrible fix is to change line 142 to:
    Code (CSharp):
    1. var baseTypeRef = arg?.BaseType;
    But I have to keep remaking this change as the package system keeps resetting it
     
  12. JPrzemieniecki

    JPrzemieniecki

    Joined:
    Feb 7, 2013
    Posts:
    33
    Another "Something went wrong" error. Having this
    Code (CSharp):
    1. class FontRef : IComponentData
    2. {
    3.     public TMPro.TMP_FontAsset Font;
    4. }
    anywhere in the project using Entities 0.3 causes the build to fail with the following error:
    Code (csharp):
    1.  
    2. Something went wrong while Post Processing the assembly (Assembly-CSharp.dll) :
    3.  Member 'UnityEngine.TextCore.Glyph' is declared in another module and needs to be imported
    4.   at Mono.Cecil.MetadataBuilder.LookupToken (Mono.Cecil.IMetadataTokenProvider provider) [0x0003c] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    5.   at Mono.Cecil.SignatureWriter.MakeTypeDefOrRefCodedRID (Mono.Cecil.TypeReference type) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    6.   at Mono.Cecil.SignatureWriter.WriteTypeSignature (Mono.Cecil.TypeReference type) [0x00161] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    7.   at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature (Mono.Cecil.IGenericInstance instance) [0x00021] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    8.   at Mono.Cecil.SignatureWriter.WriteTypeSignature (Mono.Cecil.TypeReference type) [0x000cf] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    9.   at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature (Mono.Cecil.IGenericInstance instance) [0x00021] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    10.   at Mono.Cecil.MetadataBuilder.GetMethodSpecSignature (Mono.Cecil.MethodSpecification method_spec) [0x00023] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    11.   at Mono.Cecil.MetadataBuilder.CreateMethodSpecRow (Mono.Cecil.MethodSpecification method_spec) [0x00012] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    12.   at Mono.Cecil.MetadataBuilder.GetMethodSpecToken (Mono.Cecil.MethodSpecification method_spec) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    13.   at Mono.Cecil.MetadataBuilder.LookupToken (Mono.Cecil.IMetadataTokenProvider provider) [0x000cb] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    14.   at Mono.Cecil.Cil.CodeWriter.WriteOperand (Mono.Cecil.Cil.Instruction instruction) [0x00229] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    15.   at Mono.Cecil.Cil.CodeWriter.WriteInstructions () [0x0002c] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    16.   at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody (Mono.Cecil.MethodDefinition method) [0x0002e] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    17.   at Mono.Cecil.Cil.CodeWriter.WriteMethodBody (Mono.Cecil.MethodDefinition method) [0x0002b] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    18.   at Mono.Cecil.MetadataBuilder.AddMethod (Mono.Cecil.MethodDefinition method) [0x00013] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    19.   at Mono.Cecil.MetadataBuilder.AddMethods (Mono.Cecil.TypeDefinition type) [0x00013] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    20.   at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x000a2] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    21.   at Mono.Cecil.MetadataBuilder.AddTypes () [0x00018] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    22.   at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00014] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    23.   at Mono.Cecil.MetadataBuilder.BuildModule () [0x0009f] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    24.   at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    25.   at Mono.Cecil.ModuleWriter+<>c.<BuildMetadata>b__2_0 (Mono.Cecil.MetadataBuilder builder, Mono.Cecil.MetadataReader _) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    26.   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet] (TItem item, System.Func`3[T1,T2,TResult] read) [0x00025] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    27.   at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x0000f] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    28.   at Mono.Cecil.ModuleWriter.Write (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x000fb] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    29.   at Mono.Cecil.ModuleWriter.WriteModule (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x00002] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    30.   at Mono.Cecil.ModuleDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00019] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    31.   at Mono.Cecil.AssemblyDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
    32.   at Unity.Entities.CodeGen.EntitiesILPostProcessors.Process (Unity.CompilationPipeline.Common.ILPostProcessing.ICompiledAssembly compiledAssembly) [0x000df] in C:\Projects\Tests\ECSTests\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\EntitiesILPostProcessor.cs:58
    33.   at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.RunILPostProcessors (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.String outputTempPath) [0x0011b] in <cdd38c6cb7c446c6ac90945c7521da61>:0
    34.   at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.PostProcess (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.Collections.Generic.List`1[T] messages, System.String outputTempPath) [0x00061] in <cdd38c6cb7c446c6ac90945c7521da61>:0
    35.  
    (works fine in the editor)
     
  13. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    @linfuqing
    I had this error as well and had to downgrade the Collections package. I'm using URP in 2019.3.0f3 on mac with .NET4
     
  14. JohnHudeski

    JohnHudeski

    Joined:
    Nov 18, 2017
    Posts:
    126
    Code (CSharp):
    1. Something went wrong while Post Processing the assembly (Assembly-CSharp.dll) :
    2. Failed to resolve System.Collections.Generic.Queue`1
    3.   at Unity.Entities.CodeGen.TypeReferenceExtensions.CheckedResolve (Mono.Cecil.TypeReference typeReference) [0x00000] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\CecilExtensionMethods.cs:13
    4.   at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.<VerifyMethod>g__IsTypeRestrictedToBlobAssetStorage|3_0 (Mono.Cecil.TypeReference tr, Unity.Entities.CodeGen.BlobAssetSafetyVerifier+<>c__DisplayClass3_0& ) [0x000a1] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\BlobAssetSafety\BlobAssetSafetyVerifier.cs:64
    5.   at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.VerifyMethod (Mono.Cecil.MethodDefinition method, System.Collections.Generic.HashSet`1[T] _nonRestrictedTypes) [0x0004d] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\BlobAssetSafety\BlobAssetSafetyVerifier.cs:90
    6.   at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.AssertNoBlobAssetLeavesBlobAssetStorage () [0x0004d] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\BlobAssetSafety\BlobAssetSafetyVerifier.cs:37
    7.   at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.PostProcessImpl () [0x00007] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\BlobAssetSafety\BlobAssetSafetyVerifier.cs:20
    8.   at Unity.Entities.CodeGen.EntitiesILPostProcessor.PostProcess (Mono.Cecil.AssemblyDefinition assemblyDefinition, System.Boolean& madeAChange) [0x00007] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\EntitiesILPostProcessor.cs:231
    9.  
    I got this from upgrading collections to preview 6 0.0.4
     
  15. spaceemotion

    spaceemotion

    Joined:
    Sep 29, 2015
    Posts:
    95
    @Lucas-Meijer I'd like to provide a scenario in which generics can be helpful, as I just got the following message while trying to add generics support:

    Code (CSharp):
    1. Unexpected error while post-processing XXXXXXXXX.ECS.Systems.MouseAbsorptionSystem`1:OnUpdate. Please report this error.
    2. Object reference not set to an instance of an object
    3.   at Unity.Entities.CodeGen.TypeReferenceExtensions.TypeImplements (Mono.Cecil.TypeReference typeReference, System.Type interfaceType) [0x00015] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\CecilExtensionMethods.cs:60
    4.   at Unity.Entities.CodeGen.TypeReferenceExtensions.IsIComponentDataStruct (Mono.Cecil.TypeDefinition typeDefinition) [0x00000] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\CecilExtensionMethods.cs:31
    5.   at Unity.Entities.CodeGen.InjectAndInitializeEntityQueryField.WithAllTypeArgumentForLambdaParameter (Mono.Cecil.ParameterDefinition p) [0x00029] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\InjectAndInitializeEntityQueryField.cs:288
    6.   at (wrapper delegate-invoke) System.Func`2[Mono.Cecil.ParameterDefinition,System.ValueTuple`2[Mono.Cecil.TypeReference,System.Boolean]].invoke_TResult_T(Mono.Cecil.ParameterDefinition)
    7.   at System.Linq.Enumerable+SelectArrayIterator`2[TSource,TResult].MoveNext () [0x0003a] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
    8.   at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].MoveNext () [0x0004e] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
    9.   at System.Collections.Generic.LargeArrayBuilder`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] items) [0x0005e] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
    10.   at System.Collections.Generic.SparseArrayBuilder`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] items) [0x00000] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
    11.   at System.Collections.Generic.SparseArrayBuilder`1[T].ReserveOrAdd (System.Collections.Generic.IEnumerable`1[T] items) [0x00017] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
    12.   at System.Linq.Enumerable+Concat2Iterator`1[TSource].ToArray () [0x00015] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
    13.   at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
    14.   at Unity.Entities.CodeGen.InjectAndInitializeEntityQueryField.AddGetEntityQueryFromMethod (Unity.Entities.CodeGen.LambdaJobDescriptionConstruction descriptionConstruction, Mono.Cecil.ParameterDefinition[] closureParameters, Mono.Cecil.TypeDefinition typeToInjectIn) [0x002cf] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\InjectAndInitializeEntityQueryField.cs:228
    15.   at Unity.Entities.CodeGen.InjectAndInitializeEntityQueryField.InjectAndInitialize (Mono.Cecil.MethodDefinition methodToAnalyze, Unity.Entities.CodeGen.LambdaJobDescriptionConstruction descriptionConstruction, Mono.Collections.Generic.Collection`1[T] closureParameters) [0x00048] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\InjectAndInitializeEntityQueryField.cs:42
    16.   at Unity.Entities.CodeGen.LambdaJobsPostProcessor.Rewrite (Mono.Cecil.MethodDefinition methodContainingLambdaJob, Unity.Entities.CodeGen.LambdaJobDescriptionConstruction lambdaJobDescriptionConstruction, System.Collections.Generic.List`1[T] warnings) [0x002b6] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\LambdaJobsPostProcessor.cs:334
    17.   at Unity.Entities.CodeGen.LambdaJobsPostProcessor.PostProcessImpl () [0x000b0] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\LambdaJobsPostProcessor.cs:196
    (this is using entities v0.4 preview 10)

    In our game the player can interact with various types of "elements" (fire, earth, water, ...). They all use the same base logic, except for being a different type internally.

    Each type requires buffers, several components, systems for collision, mouse and world interaction.
    Per type this is about 10 systems (which sums up to like 60 systems). The amount of copy and paste would be quite high, especially during the initial prototyping phase where we still flesh out the mechanics.

    Consolidating all elements into one component is also not a great solution, as most of the objects don't have more than 2 or 3, so that'd be just wasted memory.

    I would be grateful if you could reconsider adding generics support or give me some hints as to how not using generics could work in our use case.
     
    Last edited: Jan 5, 2020
  16. Deleted User

    Deleted User

    Guest

    Confirmed. I have the same sort of problem using TextMeshPro. Have you found any workaround?
     
  17. JPrzemieniecki

    JPrzemieniecki

    Joined:
    Feb 7, 2013
    Posts:
    33
    I wasn't really using TMP, just wanted the glyph info. My hack-around was to copy the relevant data into a ScriptableObject via an editor script. (The postprocessor crashed on anything from UnityEngine.TextCore, so you need to define your own data structure all the way down to ints/floats).

    If you need the actual font reference I belive as of Entities 0.3 there was no workaround (haven't checked since).
     
  18. Deleted User

    Deleted User

    Guest

    Thank you. I was also thinking to move everything related to UI outside of ECS components.
    I will try that.

    Cheers.
     
  19. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    85
    @wobes, I was unfortunately not able to repro the issue with the current Entities package or 0.3. Can you submit the project with a bug or include some Entities.ForEach sample code that triggers the error? Thanks.
     
  20. Deleted User

    Deleted User

    Guest

    Hi there. I decided to gave up utilizing Unity ECS for my projects and techically got no time to be Unity's QA for free.

    All the best.
     
  21. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    85
    @Sarkahn The error has been improved in the latest version of the Entities package and should now indicate which method is trying to apply to a non-captured variable in the lambda.
     
    Sarkahn likes this.
  22. Turnipski

    Turnipski

    Joined:
    Jun 27, 2015
    Posts:
    9
    @Lucas-Meijer While generics aren't ever going to be strictly necessary because one can just write a tonne of duplicate code, I've got a few use cases that would be a real pain if generics weren't involved. Here's the most complex one which is used to synchronise data from ECS to my UI models:

    Code (CSharp):
    1.  
    2. public abstract class InspectableComponentModel : IComponentData {
    3.     public Entity AssociatedEntity { get; set; }
    4.     public RemoteEntityId AssociatedRemoteEntityId { get; set; }
    5. }
    6.  
    7. [UpdateAfter(typeof(InspectEntitySystem))]
    8. public abstract class SynchronizeInspectedModelSystem<TComponent,TModel> : ComponentSystem
    9.     where TComponent : struct, IComponentData
    10.     where TModel : InspectableComponentModel, new()
    11. {
    12.     public struct LastComponentData : ISystemStateComponentData {
    13.         public TComponent Value;
    14.     }
    15.  
    16.  
    17.     private EntityQuery _addQuery, _synchronizeQuery, _removeQuery;
    18.  
    19.      [Zenject.Inject]
    20.      private DiContainer _diContainer = null;
    21.  
    22.     private bool _isZeroSized;
    23.  
    24.     protected virtual bool Interleave => true;
    25.  
    26.     protected override void OnCreate() {
    27.         _addQuery = GetEntityQuery(
    28.                                    ComponentType.ReadOnly<InspectedEntity>(),
    29.                                    ComponentType.ReadOnly<RemoteEntityId>(),
    30.                                    ComponentType.ReadOnly<TComponent>(),
    31.                                    ComponentType.Exclude<LastComponentData>()
    32.         );
    33.      
    34.         _synchronizeQuery = GetEntityQuery(
    35.                                    ComponentType.ReadOnly<InspectedEntity>(),
    36.                                    ComponentType.ReadOnly<TComponent>(),
    37.                                    ComponentType.ReadOnly<TModel>(),
    38.                                    ComponentType.ReadWrite<LastComponentData>()
    39.                                   );
    40.      
    41.         // TODO(DR): Figure out why this is filtering out actual changes and fix it so we're not always having to run checks. Could always jobify the checks
    42.         //_synchronizeQuery.SetFilterChanged(ComponentType.ReadOnly<TComponent>());
    43.      
    44.         _removeQuery = GetEntityQuery(
    45.                                    ComponentType.Exclude<InspectedEntity>(),
    46.                                    ComponentType.ReadOnly<TComponent>(),
    47.                                    ComponentType.ReadOnly<TModel>(),
    48.                                    ComponentType.ReadOnly<LastComponentData>()
    49.                                   );
    50.  
    51.         _isZeroSized = TypeManager.IsZeroSized(TypeManager.GetTypeIndex(typeof(TComponent)));
    52.      
    53.     }
    54.  
    55.     protected override unsafe void OnUpdate() {
    56.         using (var buffer = new ManagedComponentCommandBuffer(_addQuery.CalculateEntityCount())) {
    57.      
    58.             void CreateModel(Entity entity, RemoteEntityId remoteEntityId, TComponent component) {
    59.                 var model = new TModel {
    60.                     AssociatedEntity = entity,
    61.                     AssociatedRemoteEntityId = remoteEntityId
    62.                 };
    63.                 _diContainer.Inject(model);
    64.      
    65.                 Synchronize(component, model);
    66.                 buffer.AddComponent(entity, model);
    67.      
    68.                 PostUpdateCommands.AddComponent(entity, new LastComponentData() {
    69.                     Value = component
    70.                 });
    71.      
    72.                 var inspectedEntity = EntityManager.GetComponentObject<InspectedEntity>(entity);
    73.              
    74.                 var models = inspectedEntity.ComponentModels.Value;
    75.                 var newModels = models.Add(model);
    76.              
    77.                 inspectedEntity.ComponentModels.SetValue(newModels).Play();
    78.             }
    79.      
    80.             if (_isZeroSized) {
    81.                 Entities.With(_addQuery).ForEach((Entity entity, ref RemoteEntityId remoteEntityId) => CreateModel(entity, remoteEntityId, default));
    82.             } else {
    83.                 Entities.With(_addQuery).ForEach((Entity entity, ref RemoteEntityId remoteEntityId, ref TComponent component) => CreateModel(entity, remoteEntityId, component));
    84.      
    85.                 if (!Interleave || InterleaveUtil<TComponent>.ShouldExecute) {
    86.                     Entities
    87.                         .With(_synchronizeQuery)
    88.                         .ForEach((Entity entity, TModel model, ref TComponent component, ref LastComponentData lastSyncedComponent) => {
    89.                             if (UnsafeUtility.MemCmp(UnsafeUtility.AddressOf(ref lastSyncedComponent),
    90.                                                      UnsafeUtility.AddressOf(ref component),
    91.                                                      UnsafeUtility.SizeOf<TComponent>()) == 0) {
    92.                                 return;
    93.                             }
    94.      
    95.                             PostUpdateCommands.SetComponent(entity, new LastComponentData() {
    96.                                 Value = component
    97.                             });
    98.                             Synchronize(component, model);
    99.                         });
    100.                 }
    101.             }
    102.          
    103.             buffer.Flush(EntityManager);
    104.         }
    105.  
    106.         EntityManager.RemoveComponent<LastComponentData>(_removeQuery);
    107.         EntityManager.RemoveComponent<TModel>(_removeQuery);
    108.     }
    109.  
    110.     protected abstract void Synchronize(TComponent component, TModel model);
    111. }
    112.  
    113. [UpdateInWorld(UpdateInWorld.TargetWorld.Client)]
    114. [UpdateInGroup(typeof(PresentationSystemGroup))]
    115. public class SynchronizeViewportBoundsModel : SynchronizeInspectedModelSystem<ViewportBounds, ViewportBoundsModel> {
    116.     protected override bool Interleave => false;
    117.  
    118.     protected override void Synchronize(ViewportBounds component, ViewportBoundsModel model) {
    119.         model.Min.SetValue((Vector2)component.Min).Play();
    120.         model.Max.SetValue((Vector2)component.Max).Play();
    121.     }
    122. }
    123.  
    I guess the only workaround right now is to use the old style of system? i.e.
    EntityQuery.ToComponentDataArray

    If it really isn't possible to use generics or adds too much complexity to provide any time soon, would it be possible to get something like
    Entities.WithoutPostProcessing()
    so that we can opt out in cases where we think the performance hit is acceptable?

    Thanks!
     
  23. Turnipski

    Turnipski

    Joined:
    Jun 27, 2015
    Posts:
    9
    So I managed to resolve some other issues around Post Processing and managed to create a build again using 2019.3. The Post Processor didn't actually complain at all about the above system, so is this actually supported because it's in an abstract class so not processed and all the concrete types fully specify the generic parameters?