Improbable Icon

How to get gameobject reference from an entityID on on the GameLogicWorker

Hi,
What is the new way of finding GameObject based on the entityID on the GameLogicWorker?

When I’m making this line:
foreach (var entity in GameObject.FindObjectsOfType<LinkedEntityComponent>
I’m receiving the list of UnityClient and UnityGameLogic entites in my Development Scene.
What is the proper way?

reference:
https://forums.improbable.io/t/gameobject-reference-from-an-entityid/2054
https://forums.improbable.io/t/find-gameobject-with-entityid/5535

Hey @Wader,

I did a quick and dirty test using LinkedEntityComponentrunning on the latest SDK version and it worked fine

My code

[Require] private EntityId entityId;
...
Debug.Log($"My EntityID is = " + entityId);
foreach (var go in FindObjectsOfType<LinkedEntityComponent>())
{
        if (go.GetComponent<LinkedEntityComponent>().EntityId == entityId)
        {
            Debug.Log($"entityId var = " + entityId + " gameobject entityID = " + go.GetComponent<LinkedEntityComponent>().EntityId + " - That's me!");
        }
        else
        {
            Debug.Log($"entityId var = " + entityId + " gameobject entityID = " + go.GetComponent<LinkedEntityComponent>().EntityId + " - Not me...");
        }
} 

And the output on Unity’s console (I only had two entities so the result is correct)