Hello,
I’m making an editor script for a custom editor that works through the scene view. I have a few object that I made non-selectable and non-editable in the scene view with HideFlags. I have a parent of these objects that I still want to be selectable by clicking on the object (which is only made visible by children meshes). (So that editing of the children goes through the parent) So I made an OnSceneGUI function on the parent, and cast a ray to see if it hits a child. I want to make it select the parent if this succeeds. I know that it is succeeding with the ray cast because I log it, but it seems to be deselected immediately. I think either Event.Current.Use() isn’t working or that it’s still deselecting the objects even if the event is used. Here’s the code:
public void OnSceneGUI()
{
if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseUp)
{
if (Event.current.button == 0)
{
Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(worldRay, out hitInfo))
{
if (hitInfo.transform.name.StartsWith("Terrain Section"))
{
Object[] transforms = new Transform[1];
transforms[0] = (Object)hitInfo.transform.parent;
Selection.objects = transforms;
}
}
}
}
}
Thanks.