I’m doing a script that finds a particular entity with a particlar data on a component for debugging purposes.
Once you do the query and find the entity, how do I simulate the same effect when you’re navigating the Entities windows, when you select an entity and it shows up in the Inspector?
Are there methods to do this?
The thing you want to call is Unity.Entities.Editor.EntitySelectionProxy.SelectEntity(World,Entity)
EntitySelectionProxy is internal, so that’s a spot for either reflection or asmref.
I’ve never used reflection in this type of context where the class itself is hidden.
I can’t do:
var entitySelectionProxyType = typeof(Unity.Entities.Editor.EntitySelectionProxy);
because the class itself returns an error.
How do I do this?
System.Type.GetType("Unity.Entities.Editor.EntitySelectionProxy,Unity.Entities.Editor")
2 Likes
For future reference:
// Use reflection to access the EntitySelectionProxy.SelectEntity method
Type entitySelectionProxyType = Type.GetType("Unity.Entities.Editor.EntitySelectionProxy,Unity.Entities.Editor");
// Check if the Type object is not null
if(entitySelectionProxyType != null)
{
// Access the private method "SelectEntity" using reflection
var selectEntityMethod = entitySelectionProxyType.GetMethod("SelectEntity");
// Check if the method is not null
if(selectEntityMethod != null)
{
// Invoke the private method
selectEntityMethod.Invoke(null, new object[] { entityManager.World, entity });
}
}
1 Like