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.

TMP solution for DOTS?

Discussion in 'Entity Component System' started by TarikLarbaoui, Nov 29, 2020.

  1. TarikLarbaoui

    TarikLarbaoui

    Joined:
    Jul 4, 2020
    Posts:
    14
    Hey I'm building a "Twitch Plays". Considering the possible high number of players I chose to give DOTS a try and the performance savings have been quite nice. https://imgur.com/a/FWvfMRY https://imgur.com/a/bhs6aed

    In the GIF I basically spawn a character everytime someone types anything in the twitch.tv/rocketleague channel. The usernames and messages are logged in the console. They are all spawned from code :

    Code (CSharp):
    1.  void Start()
    2.     {
    3.         // connect to twitch channel
    4.         Connect();
    5.  
    6.         // setup references to World and EntityManager
    7.         defaultWorld = World.DefaultGameObjectInjectionWorld;
    8.         entityManager = defaultWorld.EntityManager;
    9.  
    10.         // generate Entity Prefab
    11.         if (gameObjectPrefab != null)
    12.         {
    13.             blobAssetStore = new BlobAssetStore();
    14.             GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(defaultWorld, blobAssetStore);
    15.             entityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPrefab, settings);
    16.  
    17.         }
    18.     }
    19.  
    20.     private void InstantiateEntity(string chatName)
    21.     {
    22.      
    23.         Entity myEntity = entityManager.Instantiate(entityPrefab);
    24.         entityManager.SetComponentData(myEntity, new PlayerData
    25.         {
    26.             chatName = new NativeString64(chatName)
    27.         });
    28.     }
    except for the one I put in the scene manually, which retains his TextMeshPro component by me adding the Convert to entity, mode : Convert and inject script on the TMP component.
    upload_2020-11-29_14-56-0.png


    This however doesn't work when I add the same script to the same prefab from which I spawn my entities. (The "entityPrefab" variable in my code above.)

    So my question is what is the best method to display usernames above the players?

    Ideal solution : Is there a way to display a textmesh in DOTS? Whether it be pure DOTS or some conversion workflow. As you can see for my needs, it really doesn't need all the features that TextMeshPro has.

    Plan B solution : Although I'm anticipating a performance hit, how would I convert and inject from code the same way I did it manually?

    Thank you very much. I'm happy to post more code, pictures, gifs, answer questions from less advanced devs who want to know how I did this and thank you in advance for your wisdom, forum gods.

    Edit : Don't know how to put the Help wanted tag.
     
    Last edited: Nov 29, 2020