Can't assign main camera to script

I’m in Unity 2018.4.30f1, and I just wrote a script for a gun that shoots physics objects away with force. Anyway, I had to make a camera variable for this, but when I go to assign the Camera component in the inspector, I drag it over the field, it shows it can be set and then… absolutely nothing happens. The variable isn’t assigned, there is no error thrown, and even using GetComponent, I still can’t get it to work. Any ideas as to why this is happening?

This is a pretty basic feature of Unity and it would be very surprising to me if it is actually broken. Can you share some screenshots of what your inspector looks like and what exactly you’re trying to drag into the slot?

https://i.gyazo.com/5b3d71a2f6fe43a9f3bcdbd804d29b60.mp4
https://i.gyazo.com/487aef01a19a8f3367826b35600c1b77.png

1st link is a GIF of me trying to get it to work, the 2nd is a picture of the whole screen

Any chance you could share your ForceGun code?

Sure thing:

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

public class ForceGun : MonoBehaviour
{
    float range = 50f;
    float force = 100f;

    bool canShoot;

    public Camera playerCam;
   
    // Start is called before the first frame update
    void Start()
    {
        //playerCam = GetComponent<Camera>();
        if(playerCam == null)
        {
            Debug.LogError("No Camera");
        }
        canShoot = true;
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetButtonDown("Fire1"))
        {
            Fire();
        }
    }

    void Fire()
    {
        RaycastHit hit;

        //Fires raycast and then checks whether the hit object has a Rigdbody
        if(Physics.Raycast(playerCam.transform.position, playerCam.transform.forward, out hit, range))
        {
            Rigidbody hitRb = hit.transform.GetComponent<Rigidbody>();
            if(hitRb != null)
            {
                //Pushes away the hit gameObject
                hitRb.AddForce(playerCam.transform.forward * force);
            }
            Debug.Log(hit.transform.name);
        }

    }
}

Ok from everything you’ve shared here this is indeed strange. It should work with the setup you have…

What happens if instead of dragging the component into the field, you drag the “Main Camera” object from the hierarchy window on the left side of the screen into that slot? That should also work.

That wasn’t working before, but apparently prefabs fix everything! UGH!
Works like a charm now. Thanks for the help. Again. God, it’s weird how many times our paths have crossed on the forum

Odd, I tried the same script, no issues assigning the camera using either method.