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

Question How to convert gameobject into entity for Dots 1.0

Discussion in 'Entity Component System' started by D_Kond, Oct 9, 2022.

  1. D_Kond

    D_Kond

    Joined:
    Mar 3, 2015
    Posts:
    25
    I can't find the way how to do that
     
    andreyakladov likes this.
  2. bb8_1

    bb8_1

    Joined:
    Jan 20, 2019
    Posts:
    98
    I think you must use subscenes and bakers(use bakers for example to convert prefabs to entity and then instantiate that prefab-entity later from the code) to convert GameObject to Entity here is tutorial : https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/DOTS_Guide - go ecs tutorial - i think there is no other way to convert except this one (basically other ways which means converting outside of subscene like in 0.51 ConvertToEntity tricks are not supported any more).
     
    Elmroot likes this.
  3. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    939
    Look at episode 4 (second half) and 5 of my dots training (link in my signature).
    It will take you through the migration of a simple project in 0.51 to 1.0 and explain the baking workflow. ;)
     
    Elmroot and bb8_1 like this.
  4. D_Kond

    D_Kond

    Joined:
    Mar 3, 2015
    Posts:
    25
    Right, it turned out that a game object must be placed on the subscene :) Thank you
     
    bb8_1 likes this.
  5. andreyakladov

    andreyakladov

    Joined:
    Nov 11, 2016
    Posts:
    29
    I'm completely stuck with this. What is the workflow if I need to load GameObjects as prefabs programmatically? How do I add them onto SubScene? Should I add a SubScene into every level scene or I can just create one programmatically once level scene loaded? Ideal would to be add SubScene programmatically and then add/convert GameObjects from prefabs to it. But I can not find the way to do it.
    If I add GameObjects with Mono and Bakers into SubScene in Scene Editor - it works just fine. But I need to be able to add lots of prefabs on every level scene once loaded. Thanks for any advice.
     
    soargon likes this.
  6. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,194
    I have a partial solution - it "works", but only if the mesh is on the root gameobject of the prefab.
     
  7. kobechenyang

    kobechenyang

    Joined:
    Jan 16, 2013
    Posts:
    6
    This is really a deal breaker. How do you use Entities with asset bundles?
     
  8. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    87
    I'm using Entities but not the Graphics package. Putting a GameObject with a Mesh/Material into a SubScene causes it to disappear. That's just unacceptable for the project I'm working on. I need something like Convert To Entity. I tried creating my own with a custom authoring script in MonoBehaviour but as soon as the entity is created and the GameObject is destroyed it throws an error saying the EntityManager has been destroyed.

    I also hate how they've removed the Asset Menu to automatically create Components/Authoring/System scripts. It's also very buggy when using Unity in a 2D project. Not very much liking Entities 1.0 so far. Keep going back to 0.51.
     
  9. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    939
    Adding back the asset menu to create dots related script is relatively easy.
    I've put mine on GitHub so feel free to use them.
    https://github.com/WAYN-Games/DOTS-Script-Templates

    If you are not using the graphics API you will have to use the hybrid approach.
    I did a video that cover how to use it for animated character.


    If you are using only this approach you may even be able to improve on it and not have to rely on a prefab which would make the authoring experience better.
     
  10. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    87
    I'm using Graphics.DrawMeshInstanced. I use GameObjects so that I have a visual representation of what I'm working with in scene view then the GameObjects are destroyed (Convert to Entity as I'm currently using 0.51) and everything is rendered using Graphics.DrawMeshInstanced, inside a SystemBase, exactly as they are seen in the scene view.

    Seems in order to do anything remotely similar in 1.0 you have to do a lot of hacky stuff.