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. Dismiss Notice

Question Windows Standalone ECS application keeps crashing on launch

Discussion in 'Entity Component System' started by lavos2300, May 26, 2023.

  1. lavos2300

    lavos2300

    Joined:
    Jun 15, 2015
    Posts:
    10
    Every time I build a standalone version of my ECS project, it crashes on startup.
    Unfortunately, I can't find much usable information in the logs, apart from this line:

    0x00007FFF1A10B6C0 (lib_burst_generated) [C:\Projects\Evolution\Unity\Library\PackageCache\com.unity.burst@1.8.4\.Runtime\Library\PackageCache\com.unity.entities@1.0.0-pre.65\Unity.Entities\Iterators\EntityQuery.cs:1420] Unity.Entities.EntityQueryImpl::Unity.Entities.EntityQueryImpl.GetSingleton<WorldProperties>

    I think the game runs without loading my scene's subscene. That's probably why it can't find the WorldProperties component, but I'm not sure. Everything works fine in the editor. Could you please advise me?
     
  2. lavos2300

    lavos2300

    Joined:
    Jun 15, 2015
    Posts:
    10
    Any idea where to look next ? I am completely stuck here... :/
     
  3. JohnnyTurbo

    JohnnyTurbo

    Joined:
    May 17, 2017
    Posts:
    36
    If I had to take a guess, you are doing the GetSingleton operation in an OnCreate of a system. What is happening during the build is that the system gets created before the singleton entity exists in the world, so it is looking for a singleton that isn't there yet.

    I'd suggest a few things to resolve:
    • Move the GetSingleton operation to OnStartRunning (for ISystem systems, you can have them implement ISystemStartStop as well to get OnStartRunning and OnStopRunning lifecycle methods)
    • Add a RequireForUpdate<WorldProperties> to the OnCreate - this way OnStartRunning won't be called until an entity with a WorldProperties component exists in the world.
    Hope that helps!
     
  4. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    257
    It may also help updating your entities packages to the latest version 1.0.10. In the past updates are not shown in the package manager for the entities packages, but you can still install the packages using the new version.
     
  5. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    939
    In your build settings window, have you referenced both your scene and subscene?
     
  6. lavos2300

    lavos2300

    Joined:
    Jun 15, 2015
    Posts:
    10
    Thank you all for your advice. Unfortunately it still doesn't work.

    @WAYNGames : I did reference both the scene and the subscene in the build settings.

    @FaithlessOne : Following your advice, I updated the packages to the latest version, but unfortunately it didn't change anything. The player keeps crashing on launch and I still get the same message about "GetSingleton".

    @JohnnyTurbo : None of my GetSingleton calls are in an OnCreate of a system. I tried to use RequireForUpdate though and I got a new similar message with GetSingleton but for another component this time. When I add another RequireForUpdate for this other system, I get the same message for another singleton component and it keeps going.
    I could probably try using RequireForUpdate for each GetSingleton call and see what happens but unfortunately I have a lot of them and I really don't think this should be necessary in the first place.

    I keep thinking the subscene isn't loaded for some reasons because it seems like the systems cannot find any singleton component.
    Unfortunately, the solutions I have found about that kind of issue are pretty old and don't work with the new ECS.
    Do you have any other idea ?
     
  7. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    It's exactly necessary.
    They load asynnchronously in build, as result any access to entities lying in subscene potentially will crash your build untill you access them only when they 100% loaded (exact purpose of RequireForUpdate or any other checks by queries)
     
  8. lavos2300

    lavos2300

    Joined:
    Jun 15, 2015
    Posts:
    10
    @eizenhorn : Thanks a lot for your help. I didn't know all this.
    Following your advice, I have added RequireForUpdate checks every time GetSingleton is called. Unfortunately, my app kept crashing and there was no useful indication in the log file so I removed a few BurstCompile attributes hoping to get more information. Now the program doesn't crash anymore. Instead, it seems to load my scene but I can't see any entity and I get the following exception : "ArgumentException: Cannot find TypeIndex for type hash 15921177164565409468. Check in the debug file ExportedTypes.log of your project Logs folder (<projectName>/Logs) the corresponding Component type name for the type hash 15921177164565409468. And ensure your runtime depends on all assemblies defining the Component types your data uses."

    Unfortunately, I could not find the ExportedTypes.log file. Does anybody know where I can find it in this case ? Also does this exception look familiar ? Apparently, there was a bug related to this exception, but it has been fixed. I also tried to reimport everything but it didn't help.
     
    Last edited: Jun 2, 2023
  9. JohnnyTurbo

    JohnnyTurbo

    Joined:
    May 17, 2017
    Posts:
    36
    That file is going to be located in the Logs directory of your project files (not build files).

    I've gotten that error when trying to access a component with a native container in a build. Although this is unsupported, it seems to work in editor but not builds. Your best bet is to switch to a blob asset array for static data or dynamic buffer for dynamic/per-entity data.
     
    lavos2300 likes this.
  10. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    939
    This looks a lot like the error I got.
    I norowed it down to the usage of the standard physics authoring component.
    Try using the custom authoring component from the physics sample.
     
    lavos2300 likes this.
  11. lavos2300

    lavos2300

    Joined:
    Jun 15, 2015
    Posts:
    10
    @JohnnyTurbo : Thanks to your help, I was able to narrow down my problem to a specific component which uses a NativeParallelMultiHashMap (I am using Collections 2.1.4). I use it for the grid partitioning of my scene. I am assuming this is the reason why I still can't build.

    Can anyone think of an alternative for this case?
     
  12. oigres27

    oigres27

    Joined:
    Jun 16, 2014
    Posts:
    1
    https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/components-nativecontainers.html this link says it is possible to have native containers inside components.
    Is it possible to know if native containers inside components is not supported, it is but currently has problems or maybe we are just doing it wrong? I had to add ChunkSerializable attribute to mine unmanaged IComponentData to get it to work on editor, but in build it shows the same error as above comments.


    Maybe you could use shared components. Each sector would correspond to one value and each entity within a sector would have a shared component with that value.
     
    lavos2300 likes this.