[SOLVED] The Referenced Script On This Behaviour Is Missing

Same issue here, for me it was addressables leaving behind hidden game objects with missing scripts after quitting play mode f.e.

Copying the scene into a new file didn’t do a thing, I’m getting the same errors! :rage::rage::rage: Still, there is no solution to this even today! :frowning:

Nvm, I got it figured out.

Your script file name and public class name should be same. Like Test.cs so public class should be public class Test

6924812--812600--Screenshot_2.png

1 Like

I had a problem where the assembly definition for the script I wanted to use was referencing other editor-only assembly definitions. No build warnings, just warnings in play mode when it couldn’t find the script, and errors if any data was serialized for it.

So I’m not sure if this will help anyone else with this missing reference issue but my solution was to simply open my prefab (a ball) and remove the missing script from the inspector of the opened ball prefab. Once I did this, my errors disappeared. The script I had deleted from my scripts folder was still attached in the prefab window.

I’m fairly new to coding but I hope this helps someone!

4 Likes

Yooo thanks, That was bothering me too!

I believe the error is due to a gameObject living in the scene without a proper Transform (In my case) (don’t ask)

So, here is what I did:

_Create a dummy class “FindMe”

_Play the game

_After being prompted with the warning “The referenced script()” Stop

_Double-click the warning, so you can see the missing script on the Inspector

_Press the cork and change the missing script to FindMe

_On the same place, right-click the script and select Find Reference on Scene

_You’ll see Unity shows you an empty-empty_not-existant gameObject

_You can’t select the object because it doesn’t exist, but if you drag the created transform gizmo you will be able to delete it with Supr key

_Problem solved

Hope it makes sense to you guys. It helped me!

1 Like

Hey everyone, sorry for resurrecting this thread but I’m adding my two cents in because my issue was different than the ones I read here. For me, I was using a singleton ScriptableObject class that would load assets from a resource folder. It worked great in the IDE, but once I made builds (desktop and quest apks) I’d get the infamous error.

This threw errors:
Resources.LoadAll(“”)

Refactoring to this threw no errors!
Resources.Load(specificFileName)

3 Likes

Also resurrecting this thread, because relevant.
If you have build scripts running on a separate build machine or agent, be sure to have checked in the Unity meta files into your repository. D’oh. Basically, my builds were working locally because I was building with the Editor, which auto-generates meta files if they don’t exist. But, build machines may not do this. They would just take the existing source from a source repository and attempt to build. Without the meta files for some scripts, the scene cannot find the referenced scripts.

This has to ALWAYS be true or you are openly courting complete project disaster.

Some info about Missing script warnings, GUIDs, renaming GUIDs, etc:

https://forum.unity.com/threads/problem-with-git-and-missing-scripts.1090876/#post-7024801
https://forum.unity.com/threads/scriptable-object-data-not-read-after-loading-editor.998413/#post-6487297
https://forum.unity.com/threads/scriptable-object-data-not-read-after-loading-editor.998413/#post-6488230

EVERYTHING in Unity is connected to the above GUID, which is stored ONLY in the metafile. It is super-easy to inadvertently change it by renaming outside of Unity. Don’t do that. Instead:

  • close Visual Studio (important!)
  • rename the file(s) in Unity
  • in Unity do Assets → Open C# Project to reopen Visual Studio
  • now rename the actual classes, and MAKE SURE THE FILE NAMES DO NOT CHANGE!

If you are NOT using source control while you do this, renaming files is an EXTREMELY dangerous process. Use source control at all times so that you can trivially revert if you miss a critical step and damage your project.

Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

As far as configuring Unity to play nice with git, keep this in mind:

https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

Here’s how I use git in one of my games, Jetpack Kurt:

https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

Using fine-grained source control as you work to refine your engineering:

https://forum.unity.com/threads/when-to-make-a-separate-object-or-class-script-help-me-think-like-a-programmer-example-in-text.1048739/#post-6783740

Share/Sharing source code between projects:

https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

Setting up an appropriate .gitignore file for Unity3D:

https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

Generally setting Unity up (includes above .gitignore concepts):

https://thoughtbot.com/blog/how-to-git-with-unity

It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place.

“Use source control or you will be really sad sooner or later.” - StarManta on the Unity3D forum boards

Definitely true. As much as my issue was that meta files weren’t checked into the repo, ultimately, it was due to my gitignore already masking those files without me knowing.

I had a .gitignore at the root of the project based on VS (https://github.com/github/gitignore/blob/main/VisualStudio.gitignore). It ignores meta files because of VS.
My git repo contains a few other VS projects, so that gitignore must be moved into those VS projects separately.

It was a complete oversight on my part, and I had only discovered this when an independent autobuild was kicked off.

1 Like

Fixed my issues well and took a few seconds to do

i have this warning

The referenced script (Unknown) on this Behaviour is missing!

i have no idea how aand where is the traceback and where to search for the problem

will try the fixes above…

First click “Add Component” in the Editor. Add the script named “NameFinder”. Open your IDE (Rider, Visual Studio etc.). Fill the class with following lines.

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

public class NameFinder : MonoBehaviour
{
// Update is called once per frame
void Update()
{
Debug.Log(“Name of the object is:” + gameObject.name);
}
}

Come back to Unity and watch console while in Play mode. Name of your object should be printed each frame. If you can find it in the scene, good. Get out of the play mode and delete it.

If you can not find it in your scene, your scene file is corrupted. Close unity, open your scene file in a text editor, search for the name of your object and delete the object manually.

You may want to see how Unity stores scene objects. In my case I had to search for GUID and delete the stuff that has the same reference. (Transform and other components should be removed.)

1 Like

Simply delete the component and create a new one with the same parameters!!
it WORKS !!! 10/28/2022

For me it was related to Visual Effect Graph.
I believe I compiled an effect from the VFXG editor without saving it and kept the VFXG editor opened.
Once I saved it the warning was gone.

So this had me running around. In one of my scripts on scene A, I would asynchronously load scene B and the warning was actually being triggered from scene B. Spent way too long scouring scene A…

Just ran in to this! Removed all of the old/missing scripts from the scene, was still getting the warning.
Turned out that even tough I removed the scripts from the scene, prefabs that contained missing scripts where still generating the warning, but without the possibility to see where the warning is “coming from”.
The problem went away once I edited the prefabs and removed the references to the missing scripts.

It happens when you delete any script attached to that prefab.
All you have to do is go to your prefab folder select prefab and open prefab from your inspector at the end in the inspector when all your script are attached you will be able to see that the script you deleted is still there and waiting for a prefab just remove that script from the three dots given on top right of the script component.