Weaver Error[SOLVED]

I have absolutely no idea what is causing this error as I followed along with everything in “selecting multiple Units” but this is the first time the error has appeared:

Any help at all would be appreciated! I am stumped on this one, tried looking at some other forums but they are outdated or not relevant. I am on Unity 2020.3.11f1 if that makes a difference

Can you share your UnitSelectionHandler script? It looks you like you are trying to access network behaviours from a monoBehaviour script.

What version of Mirror are you using?

Here is the code:

using Mirror;
using UnityEngine;
using UnityEngine.InputSystem;

public class UnitSelectionHandler : MonoBehaviour
{
    [SerializeField] private RectTransform unitSelctionArea = null;
    [SerializeField] private LayerMask layerMask = new LayerMask();

    private Vector2 startPos;

    private RTSPlayer player;
    private Camera mainCamera;

    public List<Unit> SelectedUnits { get; } = new List<Unit>();
    private void Start()
    {
        mainCamera = Camera.main;
    }

    private void Update()
    {
        if(player == null)
        {
            player = NetworkClient.connection.identity.GetComponent<RTSPlayer>();
        }
        if (Mouse.current.leftButton.wasPressedThisFrame)
        {
            StartSelectionArea();
        }
        else if (Mouse.current.leftButton.wasReleasedThisFrame)
        {
            ClearSelectionArea();
        }
        else if (Mouse.current.leftButton.isPressed)
        {
            UpdateSelectionArea();
        }
    }

    private void StartSelectionArea()
    {
        foreach (Unit selectedUnit in SelectedUnits)
        {
            selectedUnit.Deselect();
        }
        SelectedUnits.Clear();

        unitSelctionArea.gameObject.SetActive(true);
        startPos = Mouse.current.position.ReadValue();
        UpdateSelectionArea();
    }
    private void UpdateSelectionArea()
    {
        Vector2 mousePos = Mouse.current.position.ReadValue();
        float areaWidth = mousePos.x - startPos.x;
        float areaHeight = mousePos.y - startPos.y;

        unitSelctionArea.sizeDelta = new Vector2(Mathf.Abs(areaWidth), Mathf.Abs(areaHeight));
        unitSelctionArea.anchoredPosition = startPos + new Vector2((areaWidth / 2), (areaHeight / 2));
    }

    private void ClearSelectionArea()
    {
        unitSelctionArea.gameObject.SetActive(false);

        if(unitSelctionArea.sizeDelta.magnitude == 0)
        {
            Ray ray = mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue());
            if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, layerMask)) { return; }
            if (!hit.collider.TryGetComponent<Unit>(out Unit unit)) { return; }
            if (!unit.hasAuthority) { return; }
            SelectedUnits.Add(unit);
            foreach (Unit selectedUnit in SelectedUnits)
            {
                selectedUnit.Select();
            }
            return;
        }

        Vector2 min = unitSelctionArea.anchoredPosition - (unitSelctionArea.sizeDelta / 2);
        Vector2 max = unitSelctionArea.anchoredPosition + (unitSelctionArea.sizeDelta / 2);
        foreach(Unit unit in player.GetMyUnits())
        {
            Vector3 screenPos = mainCamera.WorldToScreenPoint(unit.transform.position);
            if(screenPos.x > min.x && screenPos.x < max.x && screenPos.y > min.y && screenPos.y < max.y)
            {
                SelectedUnits.Add(unit);
                unit.Select();
            }
              
        }
    }
}

I am inheriting from a monobehaviour and not networkbehaviour, but according to the GitLab for the section so is Nathan I believe so I didn’t think that was an issue. I am currently using 35.1.0 and I see there is an update. I will see if that makes any difference

Updating Mirror fixed it! i had some issued with "List"s earlier and my using statement, and somehow I think that broke Mirror(because an update should not have broke it that bad) because once Mirror updated I was able to use Lists as normal again. i do have another error now :thinking: but I think most likely something I missed in the video since I couldnt test anything. Thank you!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms