Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official Experimental Entities 0.50 is Available

Discussion in 'Entity Component System' started by mfuad, Mar 16, 2022.

Thread Status:
Not open for further replies.
  1. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    We're aware about this and should have a solution for either a patch to 0.50 or 0.51. If the EntityDebugger works for you, you can continue to use that window instead to see your Systems.
     
    PhilSA, Krajca and DreamingImLatios like this.
  2. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,113
    @Fabrice_Lete Is that possible to have hotfix patch at 0.50 very soon? Currently I already spend over 2 days to upgrade my big project to 0.50 but still haven fix all the compile errors because of this issue. Too many codes need to fix one by one. :eek:
     
  3. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    You can probably automatically fix it if your IDE supports regex replacing. I know VS code has this functionality.

    If I use this search pattern:
    and replace it with:
    It should turn all instances if code like this:
    Code (CSharp):
    1. SetComponent<Translation>(targetEntity, GetComponent<Translation>(sourceEntity));
    to this:
    Code (CSharp):
    1. var translationValue = GetComponent<Translation>(sourceEntity);
    2. SetComponent<Translation>(targetEntity, translationValue);
     
    Last edited: Mar 19, 2022
  4. Tobenai

    Tobenai

    Joined:
    Oct 2, 2018
    Posts:
    1
    It seems like the code generator doesn't include Unity.Collections when you use WithDisposeOnCompletion.

    Code (CSharp):
    1.        
    2.         var targetableArray = _targetableQuery.ToEntityArray(Unity.Collections.Allocator.TempJob);
    3.  
    4.         Entities.ForEach((...) =>
    5.         {
    6.             ...
    7.         }).WithDisposeOnCompletion(targetableArray).Schedule();

    Temp\GeneratedCode\Assembly-CSharp\TargetSelectionSystem__System_1466193276.g.cs(35,10): error CS0246: The type or namespace name 'DeallocateOnJobCompletionAttribute' could not be found.

    Explicitly including Unity.Collections in the system fixes the issue.
     
  5. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    This is probably a stupid question... but in GameObjectConversionSystem there used to be a function called AddHybridComponent(). It is no longer there. What should I use instead?
     
  6. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    GameObjectConversionSystem.DstEntityManager.AddComponentObject(hybridComponent)
     
  7. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    It was deprecated, and Unity stated couple of times, that they’ll remove that, you can try to use AddComponenObject, it’s not the same, but will help recreate similar behaviour if you need that eventually.
     
    lclemens likes this.
  8. Krooq

    Krooq

    Joined:
    Jan 30, 2013
    Posts:
    194
    Thanks to everyone who worked on this update!

    I would like to express how grateful I am to all the devs that worked on the documentation and update guide!!!
    Updating has been so smooth, thank you so much!

    Keep up the great work DOTS team!
     
    Ronsu900, charleshendry and mfuad like this.
  9. ExodusOTH

    ExodusOTH

    Joined:
    Nov 30, 2017
    Posts:
    45
    So excited for 0.50, glad it feels like we're back on track again :D Thankfully too I've been lucky enough to not run into any painful breaking changes.

    One super easy to fix bug I noticed with 0.50.0-preview.24, when you create a System from right clicking in the Project files window (Right Click -> Create -> ECS -> System), the boiler plate code that it auto-populates into the .cs file does not include the now required partial keyword in the class definition.
     
  10. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    Has anyone figured out how to convert terrains made with the terrain editor into a physics collider? This code used to work the the 0.17 when placed in an IConvertGameObjectToEntity:

    Code (CSharp):
    1.     public static PhysicsCollider CreateTerrainCollider(TerrainData terrainData, CollisionFilter filter, Unity.Physics.TerrainCollider.CollisionMethod method)
    2.     {
    3.         PhysicsCollider physicsCollider = new PhysicsCollider();
    4.         int2 size = new int2(terrainData.heightmapResolution, terrainData.heightmapResolution);
    5.         Vector3 scale = terrainData.heightmapScale;
    6.  
    7.         NativeArray<float> colliderHeights = new NativeArray<float>(terrainData.heightmapResolution * terrainData.heightmapResolution, Allocator.TempJob);
    8.         var terrainHeights = terrainData.GetHeights(0, 0, terrainData.heightmapResolution, terrainData.heightmapResolution);
    9.  
    10.         for (int j = 0; j < size.y; j++) {
    11.             for (int i = 0; i < size.x; i++) {
    12.                 float h = terrainHeights[i, j];
    13.                 colliderHeights[j + i * size.x] = h;
    14.             }
    15.         }
    16.         physicsCollider.Value = Unity.Physics.TerrainCollider.Create(colliderHeights, size, scale, method, filter);
    17.         colliderHeights.Dispose();
    18.         return physicsCollider;
    19.     }
    However, now it doesn't work. It creates the entity and a physics collider for it, but I'm not sure where it puts the collider because it doesn't seem to exist (or maybe it's resized incorrectly or something). Everything falls straight down as if there is not terrain and when I turn on the Physics Debug Display script I see nothing.

    upload_2022-3-19_20-58-55.png
     
  11. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Entities with one or more Physics Components (PhysicsCollider, PhysicsMass, PhysicsVelocity, PhysicsJoint, etc.) also require a PhysicsWorldIndex in Unity.Physics 0.50.0.
     
    Spy-Shifty and lclemens like this.
  12. ReadPan_

    ReadPan_

    Joined:
    Jan 23, 2015
    Posts:
    4
    I use this code to render a model, why can't I see it?
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Rendering;
    3. using Unity.Transforms;
    4. using UnityEngine;
    5.  
    6. namespace DefaultNamespace
    7. {
    8.     public class Testing : MonoBehaviour
    9.     {
    10.         [SerializeField] private Mesh mesh;
    11.         [SerializeField] private Material mat;
    12.         private EntityManager em => World.DefaultGameObjectInjectionWorld.EntityManager;
    13.  
    14.         private void Start()
    15.         {
    16.             var archetype = em.CreateArchetype(
    17.                 typeof(LevelComponent),
    18.                 typeof(Translation),
    19.                 typeof(Rotation),
    20.                 typeof(RenderMesh),
    21.                 typeof(RenderBounds),
    22.                 typeof(LocalToWorld));
    23.             var e = em.CreateEntity(archetype);
    24.             em.SetSharedComponentData(e, new RenderMesh
    25.             {
    26.                 mesh = mesh,
    27.                 material = mat
    28.             });
    29.         }
    30.     }
    31. }
     
  13. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    Genius alert! --> @TRS6123 !! Thanks 1000x!

    I think that the PhysicsWorldIndex requirement should be on the 0.50 upgrade page since that was not a requirement until 0.50.
     
  14. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    It is mentioned in the physics package page

    But yeah, not in the general update page they added
     
  15. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    714
    Why is the new AddComponentObject behavior not described in the upgrade guide?

    It looks like the method now clones the object and adds CompanionLink components on the entity, but only for certain types like rendering Volume. That is rather annoying since it doesn't even dispose of the original object, so the component and its game object are now there twice. Furthermore, how can we DontDestroyOnLoad the newly cloned object during Authoring?

    This is a surprising and major breaking change and I think it deserves at least some explanations in the docs.
     
    mattdymott and JesOb like this.
  16. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    So is PhysicsWorldIndex supposed to replace the now deprecated and soon to be removed PhysicsExclude ? I am adding PhysicsExclude to my building prefabs so that while a player is dropping a building in the scene, it doesn't interact with the physics world. After the building is placed, I simply remove PhysicsExclude. I also use it for my ability prefabs that are physics based so the prototype prefab doesn't fall to the center of the earth. It is very easy to use.

    Since PhysicsWorldIndex a shared component, when I try to do add it in a job with ScheduleParallel(), I get a burst error.

    Code (CSharp):
    1. ecbEnd.AddSharedComponent(entityInQueryIndex, entity, new PhysicsWorldIndex { Value = 0 });
    (0,0): Burst error BC1051: Invalid managed type found for the field `EqualFn` of the struct `Unity.Entities.FastEquality.TypeInfo`.: the type `System.Delegate` is a managed type and is not supported
    at Unity.Entities.FastEquality.GetHashCode(void* dataPtr, Unity.Entities.FastEquality.TypeInfo typeInfo) (at C:\Code\Test\Library\PackageCache\com.unity.entities@0.50.0-preview.24\Unity.Entities\Types\FastEquality.cs:201)
    at Unity.Entities.FastEquality.GetHashCode(Unity.Physics.PhysicsWorldIndex lhs, Unity.Entities.FastEquality.TypeInfo typeInfo) (at C:\Code\Test\Library\PackageCache\com.unity.entities@0.50.0-preview.24\Unity.Entities\Types\FastEquality.cs:192)
    at Unity.Entities.TypeManager.GetHashCode(ref Unity.Physics.PhysicsWorldIndex val) (at C:\Code\Test\Library\PackageCache\com.unity.entities@0.50.0-preview.24\Unity.Entities\Types\TypeManager.cs:760)
    at Unity.Entities.EntityCommandBuffer.IsDefaultObject(ref Unity.Physics.PhysicsWorldIndex component, ref int hashCode) (at C:\Code\Test\Library\PackageCache\com.unity.entities@0.50.0-preview.24\Unity.Entities\EntityCommandBuffer.cs:2188)
    at Unity.Entities.EntityCommandBuffer.ParallelWriter.AddSharedComponent(Unity.Entities.EntityCommandBuffer.ParallelWriter* this, int sortKey, Unity.Entities.Entity e, Unity.Physics.PhysicsWorldIndex component) (at C:\Code\Test\Library\PackageCache\com.unity.entities@0.50.0-preview.24\Unity.Entities\EntityCommandBuffer.cs:4106)
    at LaunchPhysicsProjectileSystem.LaunchPhysicsProjectileSystem_LambdaJob_0_Job.OriginalLambdaBody(LaunchPhysicsProjectileSystem.LaunchPhysicsProjectileSystem_LambdaJob_0_Job* this, int entityInQueryIndex, Unity.Entities.Entity entity, ref Unity.Physics.PhysicsVelocity vel, ref Unity.Transforms.Translation pos, ref TargetData tgt, ref AbilityLaunchesPhysicsProjectileData projectile)
    at LaunchPhysicsProjectileSystem.LaunchPhysicsProjectileSystem_LambdaJob_0_Job.Execute(LaunchPhysicsProjectileSystem.LaunchPhysicsProjectileSystem_LambdaJob_0_Job* this, Unity.Entities.ArchetypeChunk chunk, int batchIndex, int indexOfFirstEntityInQuery) (at C:\Code\Test\Temp\GeneratedCode\Assembly-CSharp\LaunchPhysicsProjectileSystem__System_216937474.g.cs:106)
    at Unity.Entities.JobEntityBatchIndexExtensions.JobEntityBatchIndexProducer`1<LaunchPhysicsProjectileSystem.LaunchPhysicsProjectileSystem_LambdaJob_0_Job>.ExecuteInternal(ref Unity.Entities.JobEntityBatchIndexExtensions.JobEntityBatchIndexWrapper`1<LaunchPhysicsProjectileSystem.LaunchPhysicsProjectileSystem_LambdaJob_0_Job> jobWrapper, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) (at C:\Code\Test\Library\PackageCache\com.unity.entities@0.50.0-preview.24\Unity.Entities\IJobEntityBatchWithIndex.cs:972)
    at Unity.Entities.JobEntityBatchIndexExtensions.JobEntityBatchIndexProducer`1<LaunchPhysicsProjectileSystem.LaunchPhysicsProjectileSystem_LambdaJob_0_Job>.Execute(ref Unity.Entities.JobEntityBatchIndexExtensions.JobEntityBatchIndexWrapper`1<LaunchPhysicsProjectileSystem.LaunchPhysicsProjectileSystem_LambdaJob_0_Job> jobIndexWrapper, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) (at C:\Code\Test\Library\PackageCache\com.unity.entities@0.50.0-preview.24\Unity.Entities\IJobEntityBatchWithIndex.cs:934)
    While compiling job: System.Void Unity.Entities.JobEntityBatchIndexExtensions/JobEntityBatchIndexProducer`1<LaunchPhysicsProjectileSystem/LaunchPhysicsProjectileSystem_LambdaJob_0_Job>::Execute(Unity.Entities.JobEntityBatchIndexExtensions/JobEntityBatchIndexWrapper`1<T>&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)
    at <empty>:line 0
     
  17. mk1987

    mk1987

    Joined:
    Mar 18, 2019
    Posts:
    53
    I had a similar issue and if you set the layermask in RenderMesh to 1 that should hopefully fix it. The default is zero when creating a new rendermesh from scratch.
     
    Arnold_2013, Chmyke and lclemens like this.
  18. mikaelK

    mikaelK

    Joined:
    Oct 2, 2013
    Posts:
    284
    Since collections is out of preview and cannot be downgraded, I cannot anymore use the earlier version with 0.17. packages. And since I cannot get 0.50.0 to work either I cannot use entities at all at 2021 in fresh project.

    I havent tested editing the manifest directly
     
  19. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    0.50 is 2020.3.30+ only
    for 2021 you need to wait for 0.51
     
  20. gato0429

    gato0429

    Joined:
    Mar 5, 2015
    Posts:
    22
    Hello, a question, 2d physics for ECS, is it in your update plans? :) regards
     
    dannyalgorithmic and Danila24ru like this.
  21. mikaelK

    mikaelK

    Joined:
    Oct 2, 2013
    Posts:
    284
    Yes I understand that from previous post, but the issue is that Unity blocked ecs from working completely. I have not been able to find any combination that works.

    There is no way to go back to the working collections 0.15.0 in the package manager.

    Edit. tried editing the package manifest directly. Doesn't work

    Edit. modified both manifest and package lock. Then restarted editor got it finally working. Option to update to the working version appeared.

    Edit. Mixed unity windows. Its not working in 2021
     
    Last edited: Mar 21, 2022
  22. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,113
    @Fabrice_Lete I get error spamming "Exception: This method should have been replaced by codegen?" for some systems after upgraded to 0.50. Any reason why?
     
    mikaelK likes this.
  23. mikaelK

    mikaelK

    Joined:
    Oct 2, 2013
    Posts:
    284
    I have similar issues. Code that was working before is now broken. For example using local function to wrap code complains about this.variable. I have captured this.variable on a local variable and still get this error
     
  24. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    Mentioned some oddities here
    https://forum.unity.com/threads/compilation-of-issues-with-0-50.1253973/
    you can't capture values from the ForEach into a local function
     
    mikaelK and UrsusDominatus1 like this.
  25. mikaelK

    mikaelK

    Joined:
    Oct 2, 2013
    Posts:
    284
    Thanks. Any ideas why this one is not supported anymore?
    Should I use static methods? I could test it but really busy with other stuff with the project. Also I'm on 2021.

    I rely a lot on local function to quickly make some code more readable. It ain't perfect, but its better than nothing.
    To me this sounds like an issue with ECS since local function are supported pretty much everywhere
     
    Last edited: Mar 21, 2022
  26. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    969
    For the upgrade step "Add partial keyword to all SystemBase, ISystem, and ISystemBase types", how do I show the option DOTS > DOTS Compiler > Add missing partial keyword to systems while in safe mode? (because there are compiler errors)
     
    DevViktoria and Sylmerria like this.
  27. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    Are there any known bugs with Addressables and Entities 0.50?

    Before 0.50 I loaded prefabs with:

    Code (CSharp):
    1.  
    2. // happens when scene loads in a coroutine
    3. BlobAssetStore store = World.DefaultGameObjectInjectionWorld.GetExistingSystem<ConvertToEntitySystem>().BlobAssetStore;
    4. GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, store);
    5. Addressables.LoadAssetsAsync<GameObject>("group") go => {
    6. Entity prefabEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, settings));
    7. // store prefabEntity in a dictionary or something
    8. //----------------------------------------
    9. // sometime after loading finished...
    10. // lookup prefabEntity in the dictionary
    11. Entity clone = EntityManager.Instantiate(prefabEntity); // spawn a clone
    12.  
    This works fine in 0.50... until I add a Light or a Particle System to the prefab game-object. As soon as I do that, I get this runtime error:

    MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UnityEngine.Object.Instantiate[T] (T original) (at <3be1a7ff939c43f181c0a10b5a0189ac>:0)
    Unity.Entities.CompanionLink.Clone () (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities.Hybrid/Components/CompanionLink.cs:30)
    Unity.Entities.ManagedObjectClone.Clone (System.Object obj) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/Properties/ManagedObjectClone.cs:61)
    Unity.Entities.ManagedComponentStore.CloneManagedComponents (System.Int32* srcArray, System.Int32 componentCount, System.Int32* dstArray, System.Int32 instanceCount) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ManagedComponentStore.cs:746)
    Unity.Entities.ManagedComponentStore.Playback (Unity.Entities.ManagedDeferredCommands& managedDeferredCommands) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/ManagedComponentStore.cs:689)
    Unity.Entities.EntityDataAccess.PlaybackManagedChangesMono () (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityDataAccess.cs:1257)
    Unity.Entities.EntityDataAccess.PlaybackManagedDirectly (System.Boolean& didTheThing) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityDataAccess.cs:1264)
    Unity.Entities.EntityDataAccess.PlaybackManagedChanges () (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityDataAccess.cs:1273)
    Unity.Entities.EntityDataAccess.EndStructuralChanges (Unity.Entities.EntityComponentStore+ArchetypeChanges& changes) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityDataAccess.cs:390)
    Unity.Entities.EntityManager.Instantiate (Unity.Entities.Entity srcEntity) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityManager.cs:1928)
    InputController.OnBeginDropping (BeginDroppingEvent evnt) (at Assets/Scripts/Controllers/InputController.cs:145)
     
    Last edited: Mar 22, 2022
  28. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    969
    How do you solve "error DC0031: Entities.ForEach Lambda expression stores the EntityQuery with a .WithStoreEntityQueryInField invocation but does not store it in a valid field. Entity Queries can only be stored in fields of the containing SystemBase."? I'm storing the query in a member variable of the system.
     
  29. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    are you using WithStoreEntityQueryInField(ref this.query) (the this part)?
     
  30. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    969
    Yes.
     
  31. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
  32. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    969
  33. mikaelK

    mikaelK

    Joined:
    Oct 2, 2013
    Posts:
    284
    Well I hope they fix the .this issue and local functions. Don't want to downgrade my code base or find a work around.

    It was performance by default. Not performance if you write 1000 lines of long methods with comments all over. Don't want to talk about how much more there is going to be duplicate code.

    Or does someone know a better way of doing things?
     
  34. DevViktoria

    DevViktoria

    Joined:
    Apr 6, 2021
    Posts:
    94
    I just did that in non safe mode :D ..... But I think my mistake was that I did not let the burst compile part to finish before I clicked that menu and I think that could be the thing that ruined my burst cache ...
     
  35. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    969
    I'm afraid of not doing it in safe mode as there might be missing references. It's quite a big project already.
     
    DevViktoria likes this.
  36. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    248
    Missing partial keyword will not throw any error, only warnings
     
  37. Fabrice_Lete

    Fabrice_Lete

    Unity Technologies

    Joined:
    May 5, 2018
    Posts:
    55
    There are a few known issues with local functions inside Entities.ForEach, static methods are a better alternative for now. We changed the way the code generation works between 0.17 and 0.50, the new approach is a lot better overall but unfortunately introduced a few regressions. We'll get this fixed, but I can't tell you when.
     
    Harry-Wells and mikaelK like this.
  38. mikaelK

    mikaelK

    Joined:
    Oct 2, 2013
    Posts:
    284
    Good to know and thanks for the info.

    Have you noticed the package manager can get stuck in some projects?

    I cannot change the collection package version to one that is working from the package manager on new project where I imported my plugin with the automatic package installation. The packages available doesn't work with entities 0.17 on 2021.2.16.

    upload_2022-3-23_1-11-54.png

    I just tried with completely new project and there it was available. Thankfully
    upload_2022-3-23_1-31-37.png
     
  39. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,217
    I found a bug in EntityQueryDescBuilder that causes Unity to hard crash. I was trying to switch my query generation mechanism over so that it could be Burst-compatible. Here's the relevant code change: https://github.com/Dreaming381/lsss.../Core/Core/Framework/FluentQuery.cs#L448-L464

    Simply comment out the uncommented code and uncomment the commented code, then open the project, go into "title and Menu" scene, and press play. On Windows, Unity gets tossed out of the air lock without the crash reporter triggering.
     
  40. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    Sorry for replying to my own post, but I've made some progress on this issue and I think maybe someone might know how to fix it now. I'm soooo close I can taste it!!

    I load all the prefabs asynchronously via assetmanager in the introductory title-scene. Once all the assets loaded, the "Play Game" button became active and the player would press it to enter the game. The Play button simply calls:

    Code (CSharp):
    1. SceneManager.LoadScene(1, LoadSceneMode.Single);
    So here is a screenshot of the particle systems entity on the prefab entity in the title-scene before pressing play:

    upload_2022-3-22_23-33-27.png

    And here is the same object, but during game-play:

    upload_2022-3-22_23-31-57.png

    So apparently the entity stayed the exact same after pressing "play", but the particle system+renderer and the companion link went bye bye. This did not happen in 0.17 (I used that same system for over a year), but now in 0.50 it seems that gameobjects disappear between scenes.

    So now... I just have to figure out a workaround, and hopefully I can pass the info on to anyone else who runs into this when upgrading to 0.50.
     
  41. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    714
    Did you use AddHybridComponent before? Because I found out that AddComponentObject now mimics its behavior for specific types, like particles, which is to add a CompanionLink component and a cloned object to the scene that gets destroyed on scene load. Your particle system reference gets lost on conversion as it gets cloned.

    This is super annoying, and for us a deal breaker, but avoidable by doing AddComponentObject on your own Monobehavior that stores your particles system. I hope Unity will respond to that because at this point they remained silent on the issue and didn't mention it in the upgrade guide.
     
  42. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    343
    I had to make it compatible with unity 2022.1.b11 because its amazing

    i got it working nicelly!
    Im doing a repo soon for who whants it

    this is a really nice improvement for DOTS! upload_2022-3-23_14-40-39.png
     

    Attached Files:

    Last edited: Mar 23, 2022
  43. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    343
  44. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    954
    Any side effects?
    Amazing, you just achieved something where Unity needs months. :eek:
     
    rlabrecque likes this.
  45. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    760
    I should have mentioned - AddComponentObject was one of the first things I tried.

    I changed this (which used to work just fine in 0.17):
    Code (CSharp):
    1. public partial class ParticleConversionSystem : GameObjectConversionSystem
    2. {
    3.     protected override void OnUpdate()
    4.     {
    5.         Entities.ForEach((UnityEngine.ParticleSystem particleSystem) => {
    6.             AddHybridComponent(particleSystem);
    7.         });
    8.         Entities.ForEach((UnityEngine.ParticleSystemRenderer particleSystemRenderer) => {
    9.             AddHybridComponent(particleSystemRenderer);
    10.         });
    11.     }
    12. }
    to this in 0.50:
    Code (CSharp):
    1. public partial class ParticleConversionSystem : GameObjectConversionSystem
    2. {
    3.     protected override void OnUpdate()
    4.     {
    5.         Entities.ForEach((UnityEngine.ParticleSystem particleSystem) => {
    6.             DstEntityManager.AddComponentObject(GetPrimaryEntity(particleSystem), particleSystem);
    7.         });
    8.         Entities.ForEach((UnityEngine.ParticleSystemRenderer particleSystemRenderer) => {
    9.             DstEntityManager.AddComponentObject(GetPrimaryEntity(particleSystemRenderer), particleSystemRenderer);
    10.         });
    11.     }
    12. }
    However, the gameobjects still disappear after the scene change. I think the reason that this doesn't work is that the GameObjectConversionSystem runs in the title-scene and not the actual game-play scene.

    Another thing I tried unsuccessfully was adding this in the authoring IConvertGameObjectToEntity class:

    Code (CSharp):
    1.  
    2. ParticleSystem ps = GetComponentInChildren<ParticleSystem>();
    3. ParticleSystemRenderer psr = GetComponentInChildren<ParticleSystemRenderer>();
    4. if (ps) { dstManager.AddComponentObject(entity, ps); }
    5. if (psr) { dstManager.AddComponentObject(entity, psr); }
    6.  
    When do you make your calls to AddComponentObject()? Maybe I should do it in a system that starts in the second scene? That would be difficult for me because at that point, the game objects on the prefab have already been destroyed.

    [EDIT: I sorta found a "solution", but it's rather crappy. In the title-scene, instead of using LoadSceneMode.Single, I destroy all the game-objects in the title-scene and then load the next scene with LoadSceneMode.Additive. At least then I can have prefabs with particle systems and lights on them that are loaded by addressables in the title-scene in 0.50. Yuck.]
     
    Last edited: Mar 23, 2022
    Tony_Max likes this.
  46. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    343
    Haha thanks! No side effects on my end at least
     
  47. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    343
    I just found that in other PCs of my office, it doesnt triggers the CodeGen
    so systems foreachs doesnt get generated

    This is mega weird because i dont know why my computer does generate it correctly, i have tested on 3 PCs
    mine works fine and even i can see a performance gain, plus all the improvements the new update brings

    but on the other 2 PCs i cant get them to trigger the CodeGen

    does someone have any idea about that?
     
  48. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    502
    Unsure, but I wonder if installed IDE matters at all? I would not imagine so but just an idea for consideration.
     
  49. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    343
    we all have the same IDE Installed currently with the same modules, the only difference is that while i was modifying the packages for adding support i got asked 2 times something like "Seems like api has changed, do you want to update all other correspondent package parts?" and i had 3 options, "do it with all" "only with these" "do nothing"
    and in the other pcs it didnt appeared at all
     
  50. Harry-Wells

    Harry-Wells

    Joined:
    Oct 13, 2013
    Posts:
    73
    Not that it seems like it should cause consistent differences in behaviour across specific machines, but has com.unity.roslyn's existence there affected anything? That package is responsible for the codegen in 2020.3, maybe that has something to do with codegen not happening (source generator support being built-in while also having a package for that seems like a potential problem)
     
Thread Status:
Not open for further replies.