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

'EntityManager' does not contain a definition for 'GetName' and no accessible extension method 'GetN

Discussion in 'Entity Component System' started by Kirkules_, Sep 2, 2020.

  1. Kirkules_

    Kirkules_

    Joined:
    Aug 5, 2014
    Posts:
    65
    I created a new scene, and I'm getting entities by name when I load the scene UI so I can reset the simulation.

    It runs fine in the Editor, but when I try to build the player for any platform, this error is thrown:

    'EntityManager' does not contain a definition for 'GetName' and no accessible extension method 'GetName' accepting a first argument of type 'EntityManager' could be found


    Code (CSharp):
    1. void Start()
    2.     {
    3.         foreach ( var world in World.All )
    4.         {
    5.             if ( world.Name.Contains("ClientWorld") )
    6.             {
    7.                 clientWorld = world;
    8.                 clientSimulationSystemGroup = world.GetExistingSystem<ClientSimulationSystemGroup>();
    9.  
    10.                 var entities = world.EntityManager.GetAllEntities();
    11.  
    12.                 foreach (var entity in entities)
    13.                 {
    14.                     var entityName = world.EntityManager.GetName(entity);
    15.  
    16.                     if (entityName.Equals( "PlayerCapsule") )
    17.                     {
    18.                         playerCapsule = entity;
    19.                     }
    20.                     else if (entityName.Equals("EnvironmentCylinder"))
    21.                     {
    22.                         environmentCylinder = entity;
    23.                     }
    24.                     else if (entityName.Equals("EnvironmentSphere"))
    25.                     {
    26.                         environmentSphere = entity;
    27.                     }
    28.                 }
    29.             }
    30.         }
    31.     }
     
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    677
    GetName is an editor-only api. If you want to rely on names, you need to create your own Name component and use it instead (however, I do not recommend this approach, always better to use tag components instead).
     
  3. Kirkules_

    Kirkules_

    Joined:
    Aug 5, 2014
    Posts:
    65
    Excellent.. thank you for the prompt feedback.. I like the Tag approach, it's simple and straight forward.