Can we please get some sort of identifier (name, log reference to object) to which script is not properly derived. I’m working on a team, and this error means I have to check all 70+ scripts for possible causes.
Is this occurring as an error message (rather than in an alert box or something like that)? If so, is there any more information in the console window?
It’s a Debug.Warning message.
And the only other information I can see is that it’s line 166 of Monobehaviour.cpp.
I’m trying to track it down, but it’s still eluding me. However I did get a second message saying “The script referenced in Behaviour is not a Component” with no other information from the Debug.Warning. That only showed up once during an Asset Server Update.
Still no luck tracking it down, I had a few hunches (one class specifically that I recently removed Monobehaviour from) but I can’t see how it is referenced like a Monobehaviour.
Although I should double check if it’s allowed or a good idea to call StartCoroutine from a Monobehaviour for a function on a non-MonoBehaviour inheritted class.
Perhaps someone placed this particular script on a GameObject back when it used to be a monobehaviour? That would cause such a warning (since the script it’s supposed to have is no longer a monobehaviour). Simply switching the script back to monobehaviour and adding a Start function which does Debug.Log(“bla”, gameObject) should get you a link to the offending gameobject.
As for your coroutine thing, it’s perfectly fine to run coroutines from non-MonoBehaviour classes. Just be aware you will always need a MonoBehaviour (that is guaranteed to be alive for as long as you need the coroutine to run) to call the StartCoroutine on, though.
Found It!
It seemed it may have been a bug with the Assert. I started getting it again and it was now pointing to the correct location. It was a Prefab that had an entirely different class connected to it that also used to be a MonoBehaviour. It was odd because It was previously removed in an earlier commit.
For the coroutine I have a Singleton MonoBehaviour that I can allow most of my Manager classes to hook into for main event callbacks that never gets destroyed.
Happened to me too in UNITY 2019.1.3f1, using MS Visual Studio 2019 Community version 16.1.0. I don’t know what to report, so I’ll just type in the error msg: “You are trying to replace or create a Prefab from the instance “PRINTED PRICE” that contains the script ‘priceForReceipt’, which does not derive form MonoBehavior. This is not allowed. Please change the script to derive from MonoBehavior or remove it from the GameObject.”
This the entire, unaltered class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class priceForReceipt : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
Unsure, I deleted this script, and re-added a new script component to my TextMeshPro Text object, as soon as it was created, I got this same message again.
I don’t really understand your setup because your explanation was unclear at best what’s happening there, but this error usually comes up when the class name priceForReceipt and the file name isn’t the same, so check if this class is in priceForReceipt.cs the upper/lower case differences matter.
I had the same problem in 2019.1.0f2, any prefab I made had the same issue. I managed to get it working but it took closing and reopening the project then fixing any issues in other unrelated scripts. No idea what caused it but it works fine now.