Search Unity

New SubScene & ConvertToEntity workflows

Discussion in 'Data Oriented Technology Stack' started by Joachim_Ante, Mar 4, 2019.

  1. Draveler

    Draveler

    Joined:
    Jul 1, 2018
    Posts:
    62
    I've been trying out two methods of conversion - HelloECS_05 & HelloECS_06, but haven't been getting the behavior I expected.

    HelloECS_05 seems mostly driven by this logic:

    Entity prefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(Prefab, World.Active);


    which, if fed a hierarchy, does provide a LinkedEntityGroup, but does not tag the entities as prefabs. I presume I'd need to manually call "AddReferencedPrefabAsGroup(GameObject prefab)" to do so. That's all well-and-good, but HelloECS_06 really doesn't do what I'd expect.

    HelloECS_06 looks like:

    Code (CSharp):
    1. [RequiresEntityConversion]
    2.     public class HelloSpawnerProxy : MonoBehaviour, IDeclareReferencedPrefabs, IConvertGameObjectToEntity
    3.     {
    4.         public GameObject Prefab;
    5.         public int CountX;
    6.         public int CountY;
    7.  
    8.         // Referenced prefabs have to be declared so that the conversion system knows about them ahead of time
    9.         public void DeclareReferencedPrefabs(List<GameObject> gameObjects)
    10.         {
    11.             gameObjects.Add(Prefab);
    12.         }
    13.  
    14.         // Lets you convert the editor data representation to the entity optimal runtime representation
    15.  
    16.         public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    17.         {
    18.             var spawnerData = new HelloSpawner
    19.             {
    20.                 // The referenced prefab will be converted due to DeclareReferencedPrefabs.
    21.                 // So here we simply map the game object to an entity reference to that prefab.
    22.                 Prefab = conversionSystem.GetPrimaryEntity(Prefab),
    23.                 CountX = CountX,
    24.                 CountY = CountY
    25.             };
    26.             dstManager.AddComponentData(entity, spawnerData);
    27.         }
    28.     }
    I've implemented a version of this, but can't seem to actually get DeclareReferencedPrefabs to do what it says it does, automatically. If the converter is fed the root of a hierarchy, it does manage to create the correct parent-child lists, but does not create a LinkedEntityGroup, and most importantly, does not tag the root or its children as prefabs (the GameObjects being converted are indeed prefabs, and have been declared as such). Also, if the convert function's "entity" parameter is the converted entity, why is it used to create a spawner entity, which gets deleted at a later stage? Is this not the prefab from which we're instantiating? Does prefab != entity?

    Anway, in this case, do I need to call AddGameObjectOrPrefabAsGroup(GameObject prefab) to get both a prefab tag and LinkedEntityGroup added to my converted entities? I realize, I could roll my own subclass of GameObjectConversionSystem, but I'd like to do this as simply as possible, and take advantage of the automation provided.
     
  2. llMarty

    llMarty

    Joined:
    Dec 14, 2014
    Posts:
    33
    Now this is really awesome and I'm trying it out in 2019.2 right now. However, the sample does not show how to go vice versa. Let's say I have a system that modifies the component data of my entities, I seek a sample how to convert the entity data back to the GameObject. Something like a IConvertEntityToGameObject, sort of.

    I know it is possible, because Unity comes with a CopyTransformToGameObject proxy that writes the Translation and Rotation component data back to the Transform MonoBehaviour of the GameObject. But to my surprise this is just a ComponentDataProxy ...

    I tried to investigate the Unity source, but your uploaded version is not up2date. I don't find the source of CopyTransformToGameObject nor any component data and proxy sources from ECS at all.

    Can someone bring some light into this for me?
     
    Last edited: Mar 22, 2019
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    1,630
    You shouldn’t use proxy they marked as deprecated, this new workflow is replacement for them.
     
  4. Srokaaa

    Srokaaa

    Joined:
    Sep 18, 2018
    Posts:
    77
    Had anyone make it work with Prefabs holding references to other Prefabs? I have an Instance of GameObject with such MonoBehaviour:


    Code (CSharp):
    1.  public struct DebugPanel : IComponentData
    2.     {
    3.         public Entity BoardSpawnerPrefab;
    4.     }
    5.     public class DebugPanelProxy : MonoBehaviour, IConvertGameObjectToEntity, IDeclareReferencedPrefabs
    6.     {
    7.         public GameObject BoardSpawnerPrefab;
    8.  
    9.         public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    10.         {
    11.             dstManager.AddComponentData(entity, new DebugPanel
    12.             {
    13.                 BoardSpawnerPrefab = conversionSystem.GetPrimaryEntity(BoardSpawnerPrefab)
    14.             });
    15.         }
    16.  
    17.         public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
    18.         {
    19.             referencedPrefabs.Add(BoardSpawnerPrefab);
    20.         }
    21.     }
    The BoardSpawnerPrefab GameObject is a Prefab and it's conversion to Entity works fine. This prefab however holds references to other two prefabs:


    Code (CSharp):
    1.     public struct BoardSpawner : IComponentData
    2.     {
    3.         public Entity BoardSetupSentinelPrefab;
    4.         public Entity BoardPrefab;
    5.     }
    6.  
    7.     public class BoardSpawnerProxy : MonoBehaviour, IConvertGameObjectToEntity, IDeclareReferencedPrefabs
    8.     {
    9.         public GameObject BoardSetupSentinelPrefab;
    10.         public GameObject BoardPrefab;
    11.  
    12.         public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    13.         {
    14.             dstManager.AddComponentData(entity, new BoardSpawner
    15.             {
    16.                 BoardSetupSentinelPrefab = conversionSystem.GetPrimaryEntity(BoardSetupSentinelPrefab),
    17.                 BoardPrefab              = conversionSystem.GetPrimaryEntity(BoardPrefab)
    18.             });
    19.         }
    20.  
    21.         public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
    22.         {
    23.             referencedPrefabs.Add(BoardSetupSentinelPrefab);
    24.             referencedPrefabs.Add(BoardPrefab);
    25.         }
    26.     }
    27.  
    This is where conversion flow stops working. DeclareReferencedPrefabs is not called on BoardSpawnerProxy so when I call Instantiate on resulting Entities it instantiates empty Entity without any IComponentData. I also tried to add prefabs manually during Convert() with
    Code (CSharp):
    1. conversionSystem.AddReferencedPrefab(BoardPrefab);
    but it doesn't help :/ I guess it has to something to do with this comment in the sources of ConvertGameObjectToEntitySystemDeclarePrefabs:
    Code (CSharp):
    1.     [DisableAutoCreation]
    2.     class ConvertGameObjectToEntitySystemDeclarePrefabs : GameObjectConversionSystem
    3.     {
    4.         protected override void OnUpdate()
    5.         {  
    6.             //@TODO: Support prefab to prefab referencing recursion...
    7.             var declares = new List<IDeclareReferencedPrefabs>();
    8.             var prefabs = new List<GameObject>();
    9.  
    10.             Entities.ForEach((Transform transform) =>
    11.             {
    12.                 transform.GetComponents(declares);
    13.  
    14.                 foreach (var c in declares)
    15.                     c.DeclareReferencedPrefabs(prefabs);
    16.             });
    17.  
    18.             foreach (var p in prefabs)
    19.                 AddReferencedPrefab(p);
    20.         }
    21.     }
    22.  
    Any hints on how can I work around it?
     
    Last edited: Mar 23, 2019
  5. llMarty

    llMarty

    Joined:
    Dec 14, 2014
    Posts:
    33
    I don't, but after investigating the 2nd sample, I kinda understand now. The new ConversionToEntity seems to sync data back to the GameObject, but the GameObject disappears from the hierarchy, while playing (seems correct). The sample #2 runs very fine at me, however, in my own project the GameObject disappears everywhere (so it's not visible) once I set RotationSpeed and press play. I literally added RotationSpeed, RotationSpeedProxy and RotationSpeedSystem, added a Cube, attached RotationSpeedProxy and ConversionToEntity to my cube and hit play. It's like, once my entity gets modified, it glitches away. Debugging shows the system is executed and rotation is applied, but my entity gets destroyed, because the system will run only a few times.

    I've no idea why it's messed up on my project. I have the latest Unity preview.
     
  6. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    57
    So I've been playing around with it for a while and I've been thinking if as an editor only feature, is it possible to grab the gameObject's name and apply it to the entity's name as an option? It'll look quite helpful to the EntityDebugger. Unless there's already a conversion utility for that (besides EntityManager.SetName).
     
  7. llMarty

    llMarty

    Joined:
    Dec 14, 2014
    Posts:
    33
    So I have created a new project and added the scrips from sample #2 and a cube. I added both scripts (RotationSpeedProxy and ConvertToEntity) and it doesn't work, as soon as I hit play, the cube is destroyed in the world. I attached the project, could anybody tell me why this does not work?
     

    Attached Files:

    • MJ.zip
      File size:
      32.7 KB
      Views:
      69
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    1,630
    You should install Hybrid.Renderer package
     
    llMarty likes this.
  9. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    323
    I've found that scripts with IConvertGameObjectToEntity(on a child) doesn't appear to work if the root gameObject uses a ConvertToEntity with Inject? Similarly there are warnings if you place a GameObjectEntity on the child to work around this there is a warning yet in the physics examples CharacterController this seems to be how child objects are injected? Am I incorrect in this understanding?
     
    addent likes this.
  10. llMarty

    llMarty

    Joined:
    Dec 14, 2014
    Posts:
    33
    You sir, made my day. I failed so hard for not comparing the manifest.json files. Thank you!!
    But now I try to use it on a 2D sprite, and it still does not work. Does this mean the Hybrid Renderer doesn't work with Sprites so far?

    Also I still don't understand how I can make a component proxy two way, I basically need a ConvertBack interface, so I can change literally anything on my GameObject. The sample modifies a Rotation struct and it's value gets written back to the Transform, magically. How can I do the same with an own component struct?
     
    Last edited: Mar 24, 2019
  11. Hafazeh

    Hafazeh

    Joined:
    Mar 26, 2017
    Posts:
    16
    Thank you! this is awesome.
     
  12. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    360
    Hi, If GameObjectEntity is deprecated, how to sync transform (and other Monobehaviours) with its ECS component?
    More specifically, I want to update the pose of Unity Physics Colliders which is attached to animated bones and destroy its entity if the source GameObject is destroyed. I think that this setup is quite common case. Any ideas?
     
    Ham-Dongki, addent and thelebaron like this.
  13. Micz84

    Micz84

    Joined:
    Jul 21, 2012
    Posts:
    254
    You can have a look at megacity demo too.
     
  14. scotthNM

    scotthNM

    Joined:
    Apr 17, 2015
    Posts:
    3
    Hi Joachim,

    Is there a planned release number for when the lightmap baking will be supported?
     
    joshcamas likes this.
  15. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    883
    Speaking of that, will the lightmap baking be more open ended and not blackboxy for DOTS?
     
  16. esc_marcin

    esc_marcin

    Joined:
    Sep 30, 2016
    Posts:
    23
    When you hit play with a SubScene in edit mode it will have the GameObjects in the play area. Noticed this because some prefabs had PhysX collision in a test level and we expected the collision to break with SubScene but it didn't until after hitting close on the SubScene.

    Having to navigate back up to the root SubScene to hit save & close is annoying for workflow.

    It's not clear if you're required to hit Rebuild Entity Cache after making a change to a SubScene and hitting save.
     
  17. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    40
    I've also been trying to figure this out today. I'm just trying to do something simple: maintain a GameObject with a SpriteRenderer that I can update once ECS systems have run.

    "Convert and Inject Game Object" seems to be the right idea as the GameObject sticks around, I just don't know how to, for instance, update the Sprite Renderer based on information from the Entity's components.

    EDIT: Okay, I realized what I needed to do after just walking away from it for a minute, as it goes :)
    Use "Convert and Inject Game Object" to make sure the components you need get injected and the GameObject sticks around, then simply create a ComponentSystem to do what you want using an Entities.ForEach loop. So for example, if you want to move the GameObject based on the Translation component:

    Code (CSharp):
    1.     public class TranslationSystem : ComponentSystem {
    2.         protected override void OnUpdate() {
    3.             Entities.ForEach((Transform transform, ref Translation translation) => {
    4.                 transform.position = new Vector3(translation.Value.x, translation.Value.y, translation.Value.z);
    5.             });
    6.         }
    7.     }
     
    Last edited: Mar 30, 2019
    Ham-Dongki, Alverik and Kender like this.
  18. joseph-t83

    joseph-t83

    Joined:
    Mar 28, 2014
    Posts:
    22
    Has anybody added buffers to entities that they've converted to subscenes?

    I'm adding buffers to entities in a GameObjectConversionSystem and it works normally, but once I convert them to subscenes the buffers get lost. Any idea what's happening? The values get printed in the conversion process if I add a Debug.Log. So the system is running.
     
  19. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    360
    I tested ConvertToEntity and found that it works only for the top level of object hierarchy if "Convert and Inject Game Object" is selected. So I think that I should implement manual conversion routines for this case.
     
  20. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    171
    Is using IConvertEntityToData more efficient than using ComponentDataProxy?
     
  21. joseph-t83

    joseph-t83

    Joined:
    Mar 28, 2014
    Posts:
    22
    Any entities that are streamed in from subscenes that then get additional components added don't get destroyed when the subscene is unloaded. They get all their other components removed, except the new ones, and are tagged with CleanupEntity. Is there any way to find all these entities and destroy them too?
     
  22. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    40
    I just did a bug report, but just wanted to call out that SubScenes and SharedComponentData are not playing together for me. Every time I save the subScene it adds another GameObject for the SharedComponent, that object also has conflicting information in it (it wants me to remove the GameObjectEntity component, but also it is required by the SceneSection component proxy). When I do load in the SubScene at runtime it crashes Unity.
     
  23. joseph-t83

    joseph-t83

    Joined:
    Mar 28, 2014
    Posts:
    22
    Are you using SharedComponentDataProxy for your shared components? You need to use that instead of the regular iconvertgameobject.
     
  24. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    40
    Oh thank you, no I wasn't aware of that!
     
  25. joseph-t83

    joseph-t83

    Joined:
    Mar 28, 2014
    Posts:
    22
    Btw, all you need to do to setup your shared component proxy is:

    Code (CSharp):
    1. public class YourSharedComponentProxy : SharedComponentDataProxy<YourSharedComponent>{}
    Then everything that's serialized in your component will show up in the inspector.

    I just reread your post and also realized you said you're using GameObjectEntity. That is obsolete. You don't need any type of convert to entity or anything on stuff you put in subscenes. It all gets converted to entities automatically.

    You can see that, if you put a default cube in a subscene and hit play (and close the subscene first, otherwise it will crash, ofcourse). You'll end up with an entity with all the entity transforms and a rendermesh for the cube.
     
  26. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    904
    ecs_android.jpg ecs_pc.jpg
    why the batching broken on android plateform?
     
  27. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    904
    And If want to build the SubScene as abundle ,will selected the SubScene's EntiyCache Resuorces 's prefabs or the SubScene to build?And how to load the abundles with its dependence?Confused with Why need make a scene for the prefab,why not mak prefab directly with the bound volume? If SubScene With Navmesh,How to combine them?
     
    Last edited: Apr 4, 2019
  28. jooleanlogic

    jooleanlogic

    Joined:
    Mar 1, 2018
    Posts:
    332
    'Convert to Entity'->'Convert and Inject Game Object' produces NullReference exception if IConvertGameObjectToEntity MonoBehaviour includes member variables.
    Exception is only thrown when you click on the Entity in the Entity Debugger window.
    This happens in the rotation cube sample if you change it to Inject instead of 'Convert and Destroy'

     
    Abbrew likes this.
  29. Timboc

    Timboc

    Joined:
    Jun 22, 2015
    Posts:
    34
    Same happens for me and would like to see a fix. Just a quick tip for if you need to inspect the entity and are getting flooded - you can toggle the expansion of the component and that will temporarily stop the errors.
     
  30. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    360
    How about making GameObjectConversionUtility.Convert() to be public? It is need to implement for own conversion helper, which cover stiuations that ConvertToEntity can't handle.
     
  31. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    166
    I simply use one of GameObjectEntity's methods to map a GameObject to Entity, and it perfectly suits. The method, that current conversion system uses under the hood
     
  32. Brad-Newman

    Brad-Newman

    Joined:
    Feb 7, 2013
    Posts:
    112
    In the MegaCity mobile project (I think it's the same for Desktop) when you select a sub scene in the Scene view the assets don't highlight. This makes it difficult to edit sub scenes because you can't quickly visually confirm what asset is selected. To identify sub scenes visually I've resorted to enabling and disabling the sub scene to see it blink on / off as shown here:

    mRLDyQX8id.gif

    My feature request would be:
    - Select sub scene asset in Scene view (or Hierarchy)
    - Asset highlights the same way a prefab would highlight (as shown below once the sub scene is opened for editing).

    2My1VGpb33.gif
     
    Kender likes this.
  33. Timboc

    Timboc

    Joined:
    Jun 22, 2015
    Posts:
    34
    Situation: GameObject #A & #B both have a `Bob : MonoBehaviour, IConvertGameObjectToEntity` component. Bob has an exposed UnityEvent and let's say in the inspector, #A has it hooked up to call a method on #B.
    E.g. #A has an OnComplete() event that calls Bob.Start() on #B.

    Problem: How do I preserve this when I add a ConvertToEntity component to a common root of A & B? I can preserve the complete event but it no longer works (presumably as the GameObject it refers to has been destroyed). I could choose Convert & Inject however I believe that doesn't actually convert the children to entities?

    Is there a route via a System that extends GameObjectConversionSystem I wonder? If so I'm still a bit fuzzy on how I would check whether these events were calling to GameObjects that may or may not be converted and I'm wary about diving into a well of reflection o_O.

    This problem also extends to e.g. a non-converted monobehaviour calling a method on a converted monobehaviour. Like a Button having a click event hooked in to a Bob that is converted - however, I believe that is a more justified/expected case of references being lost?

    I'm concluding that it may be simply better to disallow this paradigm - i.e. not exposing a UnityEvent - but that would be a shame.

    I'd appreciate it if anyone could point out flaws in my understanding, other ways to approach the problem and/or if anyone is facing similar issues.

    (As a side note, it seems currently ConvertToEntity doesn't preserve scale & position of children of a GameObject that has a non-Vector3.one scale.)
     
    addent and Kender like this.
  34. FixItFelix

    FixItFelix

    Joined:
    Mar 27, 2017
    Posts:
    39
    When I using the Subscene and deploying my build to android it can not load the subscene from the entityCache.
    The message is:
    Error when processing
    'AsyncLoadSceneJob(jar:file///data/app/domain//base.apk!/assets/EntityCache/c5eb1f3968daa4dd1987d699742f46c1_0.entities)': Attempting to read a entity scene stored in an old file format version (stored version: 0, current version: 17).

    But just before the build I rebuild already the entity cache. I even cleared before the folder.
     
    Opeth001 likes this.
  35. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    53
    @Joachim_Ante So I tried using the subscenes to load a Grid, but the grid does not seem to load, I expect this is because 2d is not yet supported by ECS ? is there any way for me to make this work now ?
    When will ECS start to support 2d ?
     
  36. FixItFelix

    FixItFelix

    Joined:
    Mar 27, 2017
    Posts:
    39
    @DavidNLN: You have to consider that the subscene system can only handle all convertible things. And these are not so many at the moment. For example, you can not convert terrain or any 2d renderer.
    For your own components, you can implement the IConvertGameObjectToEntity.
     
  37. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    53
    @FixItFelix Hey, Thanks for the answer, As far as I read, you cannot use IconvertGameObjectToEntity for spriterenderes or tilemaps yet, am I wrong ? can you give me an example ?
     
    Last edited: Apr 12, 2019
  38. FixItFelix

    FixItFelix

    Joined:
    Mar 27, 2017
    Posts:
    39
    You are right. For unity components, I guess we have to wait for unity to convert them.

    You can use it for your own components and IComponentData. It gives you basically the possibility to have an editor for you IComponentData.

    Here you find a lot of information about it.
    https://gametorrahod.com/gameobject-conversion-ecosystem-code-tour/
     
    Last edited: Apr 12, 2019
  39. quabug

    quabug

    Joined:
    Jul 18, 2015
    Posts:
    16
    1. Is there a way to leave gameobject at runtime instead of destroy it entirely in subscene? "Convert And Inject Game Object".
    2. Is it possible to alter/delete some entities from hierarchy in subscene, usually I don't need every game objects/monobehaviors to be convert into entities/components.
     
  40. JacobWang

    JacobWang

    Joined:
    Nov 2, 2018
    Posts:
    1
    I tried using the new 'ConvertToEntity' workflow to convert a gameObject with an Animator component. Only if 'Convert and Inject Game Object' mode's selected I can get Animator component by Entities.ForEach(). But it works only for the top level of object hierarchy, and there will be 1 gameObject and 1 entity rendered in the world.
    How can I get the Animator component or other components like RigidBody and have only one object rendered in the world? Should I return to use GameObjectEntity?
     
  41. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    323
    Not showstopping as the scene plays but I get
    Code (CSharp):
    1. InvalidOperationException: GetSingleton<Unity.Entities.SceneBoundingVolume>() requires that exactly one Unity.Entities.SceneBoundingVolume exists but there are 2.
    2.  
    if there is a ConvertToEntity script in a scene with multiple subscenes. Is there a preferred way of organizing scene that has subscenes and ConvertToEntity scripts within it?
     
  42. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    806
    Is there a way to know which thread to follow?
    Like a list of things that can be converted? (box collider don't, even with unity.physics installed)
    Who's the right one to submit bugs or questions for what?

    I tried the new subscene with a big building (100x150m) made from several hundred modular parts.
    Statically batched: 40fps
    ECS converted: 50fps.
    That's great, but I had to uncheck "enable gpu instancing" to get lit objects with ecs. Who to ask? HDRP Team? ECS?

    PS:
    The emphasis is definitely on "that's great", not on the material property.
     
  43. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    109
  44. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    40
    What is the recommended way to spawn hybrid GameObjects which want to be converted to entities with "Convert and Inject Game Object"? The two methods covered in the Hello ECS samples only appear to work if you don't need the original GameObject, so I was just using GameObject.Instantiate() on my Prefab (which has the ConvertToEntity component set up as needed), but I noticed in the profiler, whenever I instantiate like this, it spends about 20ms in ConvertToEntity.Awake() with most of that spent in "Create World & Systems".
     
  45. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,226
    I was missing the automatic entity renaming from the previous gameobject scene conversion workflow with the ConvertToEntity approach. I did some digging and this is actually supported but not used currently, why it's not enabled by default?

    You can force this back on from ConvertToEntity.cs by swapping the last parameter from 0 to GameObjectConversionUtility.ConversionFlags.AssignName from those two lines that call GameObjectConversionUtility.CreateConversionWorld.
     
    Kender likes this.
  46. The-Exceptional-Bruce

    The-Exceptional-Bruce

    Joined:
    May 10, 2015
    Posts:
    27
    I have two gameobjects that implement IConvertGameObjectToEntity. Each one has a field with a reference to the other. How can I use the Convert method to get the Entity value of both and maintain the references in a component on each one. The problem is the the first gameobject converted can't get the Entity reference of the second, because it hasn't been converted yet.

    The Convert method is called from the Awake and the gameobject is destroyed before the other gameobject can be converted so I could have a parent gameobject add the components to the newly converted entities in the parent gameobjects's Convert method. I could use a GUID as a reference to translate from gameobject to GUID and GUID to the entities, but is there a better way I am not seeing?
     
    Timboc likes this.
  47. Grygus

    Grygus

    Joined:
    Aug 7, 2013
    Posts:
    18
    Hi, what about LOD cross fade after conversion to Entity? Is there any way to make it work? Even in megapolis sample, I see that they made all LODs Groups with crossfade and it works per scene in editor but after caching to entities and in builds it does not work, and there is only simple hide/show. So for subscene there is no crossfade for LODs.
     
  48. Dagarath

    Dagarath

    Joined:
    Apr 17, 2013
    Posts:
    15

    You can always use the ConvertToEntity component and set it's Conversion Mode to "Convert and Inject Game Object", that way you maintain a gameobject reference to your entity, at least I think that is how it works, at least that is how I am using it :confused:. Or I guess read the source for ConvertToEntity as I would suspect that also implements IConvertGameObjectToEntity. It comes down to what you are trying to do, and more importantly why.
     
    The-Exceptional-Bruce likes this.
  49. The-Exceptional-Bruce

    The-Exceptional-Bruce

    Joined:
    May 10, 2015
    Posts:
    27
    Thanks for the suggestion. I tried using "Convert and Inject Game Object", but it only calls the Convert method on the top level of gameobject's hierarchy so that won't work.
     
    Abbrew likes this.
  50. Dagarath

    Dagarath

    Joined:
    Apr 17, 2013
    Posts:
    15
    Oh I've run into this, each child needs the convert and inject game object, but the parent if you do not require a reference to it, does not, yhis is how I am having my camera follow my player entity, I simply added an empty game object as a child and placed ConvertToEntity in Inject gameobject mode on it, and magic happened. Of course on conversion you can always keep a reference to your entities somewhere, and make things easy. Otherwise you are stuck finding things based on components.

    And ofc you can always just do this through code. I finally looked at that today and its pretty straightforward.