Looking for how this script is called, 'Find References In Scene' isn't finding it

Hello everyone.

Weird issue, but this is driving me nuts. I can’t seem to find where or how this script is being called, but it is. I’ve done a million little things, and cobbled together Mirror tutorial scripts so many different times that I’ve forgotten where I even began or where to go next.

I’ve searched around - and found and tried the ‘right click on a script and click “Find References In Scene”’ on all of the scenes I have (which is only 3, one loading, one play, and one old unused one), but this cameracontroller call is not found.

The sample below was included in one of the Mirror tutorials, and is what is being used to follow the player. Yet it is not assigned to any of the objects, in any scene. But it is still working. How?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;

namespace UltimateCameraController.Cameras.Controllers
{
   
    public class CameraController : MonoBehaviour
    {
       
        private Camera targetCamera;

        [Header("Follow Settings")]
        [Space(10)]

        [Tooltip("Should the camera follow the target?")]
        public bool followTargetPosition = true; //Do we want our camera to follow the target object

        [Tooltip("The target object our camera should follow or orbit around")]
        //public Transform targetObject; //The object that our camera should follow
        public GameObject targetObject;


        [Tooltip("The smooth factor when the camera follows a target object")]
        [Range(0.2f, 1f)]
        public float cameraFollowSmoothness; //The smooth factor when the camera follows a target object

        [Header("Orbit Settings")]
        [Space(10)]

        [Tooltip("Should the player be able to orbit around the target object?")]
        public bool orbitAroundTarget = true; //Do we want to add orbit functionality to the camera

        [Tooltip("The speed by which the camera rotates when orbiting")]
        [Range(2f, 15f)]
        public float rotationSpeed; //The speed by which the camera rotates when orbiting

        [Tooltip("The mouse button that the player must hold in order to orbit the camera")]
        public MouseButtons mouseButton; //The mouse button that the player must hold in order to orbit the camera

        private Vector3 _cameraOffset; //How far away is the camera from the target

        private void Start()
        {
           // if (isLocalPlayer)
            //{
                targetCamera = GetComponent<Camera>();
                _cameraOffset = targetObject.transform.position + new Vector3(-10.0f, 20.0f, -24.0f);

            //}
        }

        //We use late update so that player movement is completed before we move the camera/This way we can avoid glitches
        private void LateUpdate()
        {

            //if (isLocalPlayer)
            //{

                //We do an error check
                if (targetObject == null)
                {
                    Debug.LogError("Target Object is not assigned. Please assign a target object in the inspector.");
                    return;
                }

                var players = GameObject.FindGameObjectsWithTag("Player");

                if (targetObject != null)
                {
                    foreach (var player in players)
                    {   //Debug.Log("IsNotNull5555");//works

                        targetObject = player;
                        transform.LookAt(targetObject.transform.position);

                    }
                }


                //If we want the camera to follow the target
                if (followTargetPosition)
                {
                    //We set the position the camera should move to, to the sum of the offset and the target's position
                    var newPosition = targetObject.transform.position + _cameraOffset;
                    //var newPosition = targetObject.position + _cameraOffset;
                    transform.position = Vector3.Slerp(transform.position, newPosition, cameraFollowSmoothness);
                }

                //If we want to make the player able to orbit around the target
                if (orbitAroundTarget)
                {
                    //if (isLocalPlayer)
                    //{
                        //// We call the function to orbit the camera
                        OrbitCamera();
                   // }
                }
            //}
        }

        //Method to handle Orbit of the Camera
        private void OrbitCamera()
        {
            //If the player holds the selected mouse button
            if (Input.GetMouseButton((int)mouseButton))
            {
                //We cache the mouse rotation values multiplied by the rotation speed
                float y_rotate = Input.GetAxis("Mouse X") * rotationSpeed;
                float x_rotate = Input.GetAxis("Mouse Y") * rotationSpeed;

                //We calculate the rotation angles based on the cached values and a specific axes
                Quaternion xAngle = Quaternion.AngleAxis(y_rotate, Vector3.up);
                Quaternion yAngle = Quaternion.AngleAxis(x_rotate, Vector3.left);

                //We multiply the rotation angle by the camera offset
                _cameraOffset = xAngle * _cameraOffset;
                _cameraOffset = yAngle * _cameraOffset;

                // targetCamera.LookAt(targetObject.transform.position);
                transform.LookAt(targetObject.transform.position);

                //We make our transform to "look" at the target       
                //////////transform.LookAt(targetObject.transform.position);
                //    transform.LookAt(targetObject);
            }
        }
    }

    //Custom enumerator that represents the mouse buttons
    public enum MouseButtons
    {
        LeftButton = 0,
        RightButton = 1,
        ScrollButton = 2
    };
}

It is following the player, and rotating around the player - but the “drag to pan” feature isn’t working, which is what started me down this rabbit hole.

I’d like to know when/where/how this is triggered so I can work to resolve the mouse drag pan scenario.

(or if anyone knows how to do that, that would cut out some steps)

Any thoughts?

Thanks all.

While the game is running in the editor and the camera code is running, pause the game and type t:CameraController (don’t forget the t:) in the hierarchy search bar, then you’ll have your culprit.

1 Like

Great tip, thank you Gro - but:

8155676--1059782--upload_2022-5-25_9-16-12.png

So the only other thing I can think of is that it is somehow baked into Mirror / Network code. But even then, wouldn’t it still be visible here?

The camera is certainly following the player… so strange.

Just to show I did it right, I tested with a different script and it found it
8155676--1059785--upload_2022-5-25_9-18-22.png

Since the code is doing targetCamera = GetComponent<Camera>();, surely this script must be attached to camera object. Maybe you couldn’t find it because actual component attached to camera is subclass of the one you pasted.

One more approach you can use to locate the corresponding game object is modifying that script and adding following code inside start or update methods.
Debug.Log("text doesn't matter", gameObject);

Once the debug log message is printed in console, clicking it should highlight the object in inspector. Having that debug message should also help you confirming that the corresponding script is really running instead of the camera movements you observed being caused by completely different script.

1 Like

I do feel like an idiot now. In my head, because I didn’t add it myself (and I don’t understand enough about this yet), I didn’t realize the simplicty with what was needed to follow the player.

There was a ‘floatingInfo.transform.LookAt(Camera.main.transform);’ hiding in a script, and the CameraController was indeed not in use as I thought. Which explains why I wasn’t able to track down how it was being used :slight_smile:

I appreciate both of your times. Thank you so much for your help with my silly issue.

1 Like