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

ECS and TextMeshPro

Discussion in 'Entity Component System' started by Sombrero13, May 1, 2020.

  1. Sombrero13

    Sombrero13

    Joined:
    Mar 20, 2019
    Posts:
    7
    Is there any way to make a conversion ECS system work with TextMeshPro? I need to update the text that moves with the Entity in-game and can't find a way to do it with ECS.
     
  2. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    158
    I think your best approach is to do a non bursted Entities.ForEach where you access a class reference to your TMP object. If you did not know, you can have non blittable data (classes etc.) in a IComponentData if it's a class, not a struct. Then you can access it and all of it's references (your TMP object) inside a Entities.ForEach loop called on as .WithoutBurst().Run().

    Now, I've had a lot of problem including a TMP object directly into a IComponentData class, but if you link to your own MonoBehaviour and do you text manipulation in there, it should work!
     
    florianhanke likes this.
  3. Sombrero13

    Sombrero13

    Joined:
    Mar 20, 2019
    Posts:
    7
    But what about conversion? So, for example, I have Quad with ConvertToEntity script and some Canvas or TMP as a child. Is it possible to convert TMP or/and Canvas to IComponentData and use later as fully Entity?
     
  4. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    158
    I did it by placing a Convert (Stop) on the TMP object, so it is kept as a GameObject, and just referenced it inside a class IComponentData. So it's sort of ECS based, but not bursted or possible to put in a job.
     
    florianhanke and Sombrero13 like this.
  5. Sombrero13

    Sombrero13

    Joined:
    Mar 20, 2019
    Posts:
    7
    Alright, thank you! I'll give a try
     
    Mockarutan likes this.
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,655
    AddHybridComponent in GameObjectConversionSystem, thus it will be converted with companion game object.
     
    Sombrero13 and florianhanke like this.
  7. Sombrero13

    Sombrero13

    Joined:
    Mar 20, 2019
    Posts:
    7
    Haven't heard about this approach, thank you. But as far I understand according to this example: https://github.com/Unity-Technologi.../Assets/StressTests/HybridComponent/README.md, I can't access directly to the Companion GameObject and change it. How can I change the text then from System?
     
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,655
    You convert your TMP and can access that TMP type in queries, ForEach'es (without burst and only on main thread)

    Entities.ForEach((Entity e, TMPType tmpInstance)=>{ tmpInstance.DoStuff() })
     
    Sombrero13 likes this.