ClientSim icon indicating copy to clipboard operation
ClientSim copied to clipboard

Destroying focused object breaks Client sim (Works fine in VRChat)

Open iffn opened this issue 2 years ago • 0 comments

Destroying objects that the Client sim is currently looking at seems to break the Client sim. This seems to be a Client sim issue and does not occur in VRChat.

Test:

I added a script to a cube which destroys the attached gameObject in the Interact() function. When looking at the cube and interacting with it, the Client sim breaks. Note: This also seems to happen when the GameObject is destroyed through other means such as the Editor or the Update function.

Video: https://www.youtube.com/watch?v=v583uamE2_c

Ugly hotfix:

I followed the error messages and I was able to avoid the issue by modifying 2 files. Note: I have not looked into the architecture of the code. So this is probably neither nice nor reliable.

ClientSimTooltip.cs

public void UpdateTooltip(Vector3 playerPos, Vector3 up)
{
    // Added try catch block since Interactable.GetInteractTextPlacement() fails when the GameObject has been destroyed
    Vector3 position = Vector3.zero;

    try
    {
        position = Interactable.GetInteractTextPlacement();
    }
    catch (MissingReferenceException e)
    {
        Debug.LogWarning($"Avoided exception: {e}");
    }
            
    // Rotate to look towards the player while keeping the proper up direction.
    // VRChatBug: Build 1160 has this broken again so that rotating the player through stations does not properly rotate tooltips.
    Quaternion rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(playerPos - position, up), up);
    transform.SetPositionAndRotation(position, rotation);
}

ClientSimHighlightManager.cs:

private List<Renderer> GatherRenderers(GameObject obj, bool findDisabled)
{
    List<Renderer> results = new List<Renderer>();

    // Added null pointer check
    if (obj == null)
    {
        Debug.LogWarning($"Avoided null pointer exception in {nameof(GatherRenderers)}");
        return results;
    }

    foreach (var rend in obj.GetComponentsInChildren<Renderer>(findDisabled))
    {
        if (!rend.enabled || rend.isPartOfStaticBatch)
        {
            continue;
        }
        MeshFilter filter = rend.GetComponent<MeshFilter>();
        if (filter == null || filter.sharedMesh == null)
        {
            continue;
        }
                
        results.Add(rend);
    }

    return results;
}

iffn avatar Dec 04 '22 13:12 iffn