thingToFollow is a default reference

I’m unable to add a game object to the “thing to follow” field in the editor. There’s a message saying, “Default references will only be applied in edit mode.”

public class FollowCamera : MonoBehaviour
{
	[SerializeField] GameObject thingToFollow;
	// Camera's position should match car's
  
    void Update()
    {
        
    }
}

Not sure if it’s relevant, but I have an asset called Script Inspector for editing scripts in the Unity editor.

Hi Jorin,

Welcome back to our community. :slight_smile:

Have you already tried to restart Unity and Visual Studio Code? Make sure the script is saved properly.

I do not know the Script Inspector script or where you got it from. If the problem persists, maybe you could comment the code in it out and save the script to see if that fixes the issue.


See also:

I ran into this problem before! It was because I was dragging a game object to the serialized field inside the inspector when the script itself was selected, not the thing the script was attached to. In your case, first click on the camera gameobject in your hierarchy, then scroll down to the script component in your inspector, and drag the target gameobject to the serialized field thingToFollow while the inspector is still on the camera.

If your inspector looks like this, you are trying to populate the serialized field directly in this script (which is wrong.):

You should be able to drag the GameObject into the field in the inspector when the camera is selected:

1 Like

Thank you gamescrub, it works now. :slight_smile:

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

Privacy & Terms