Can't add scripts - "Can't add script behaviour TMP_CoroutineTween [...]".
I get this error message in a pop up while trying to add a script to a empty GameObject:
can't add script behaviour TMP_CoroutineTween
Have no idea of why. It appears insistently each time I try to drag and drop the script to the game object. Finally I closed and reopen Unity3D Editor, deleted the game object end created a new one and I was able to ad the script, so now the problem for me was solved.
But I wanted to report this because I think this could be useful to somelse that could have the same problem.
It could be a bug of the Editor, I suppose.
Answer by dctoday · Aug 16, 2018 at 09:33 AM
Answer Edit: The issue is caused when changing the script file name after creating it. The class name within the script at the top of the file must also match the file name.
Quote from documentation: The name of the class is taken from the name you supplied when the file was created. The class name and file name must be the same to enable the script component to be attached to a GameObject.
Hope this helps someone as it fixed it for me. =)
Cheerio, Cormac
Hi,
I too am having this issue in latest Unity 2018.2.3f1 where I right click in project folder and create new C# Script. I change name to CharacterBehaviourScript and it contains the default text.
Now if I try drag this onto my player object, I get the same error. I've found no way around this, so I don't think it's my script as I was following a YouTube tutorial with the exact same code.
Please advise?
Just to add this link which may be of help: https://docs.unity3d.com/$$anonymous$$anual/CreatingAndUsingScripts.html
dctoday's solution worked for me. Rena$$anonymous$$g the script and gameobjects to the same name fixed it. Thank you!
Seems like unity dropped the ball on this error message. Its completely uninformative. Terrible.
dctoday's solution did work- kylander- are you doing the pixelnest tutorial by chance?
Answer by Bunny83 · Jul 16, 2018 at 11:34 AM
If that "TMP_CoroutineTween" script file is from TextMesh Pro, then you're not supposed to add it to a gameobject. Only MonoBehaviours can be added as component to a gameobject. Not every script file contains a MonoBehaviour derived class. It seems you're using third party code here and just don't understand how to use it. So i recommend to read the documentaion of that third party product.
This is certainly no bug in Unity. As far as i can tell from a version i've found on the net, the "TMP_CoroutineTween.cs" file contains only internal classes and structs of the TextMeshPro framework.
@Bunny83, I got the same issue - added a completely unrelated script with a single, simple class extending from $$anonymous$$onoBehavior, and the error complains about T$$anonymous$$P_CoroutineTween. Restart unity, and doing the same action now complains "Can't add script behavior UICanvas...". It is behaving as if when you drag+drop from assets folder, the message sent was "add script at index 23", and then the editor looks up index 23 in a separate script array. Tried deleting and re-adding, restarting client, etc, all without success. And in case you still think this is just a class problem, here it is:
// A class to expose Unity events to non-Unity handlers
using UnityEngine;
public class EventGlue : $$anonymous$$onoBehaviour
{
EconEvent<EventArgs> UpdateEvent { get; set; } = new EconEvent<EventArgs>();
EconEvent<EventArgs> FixedUpdateEvent { get; set; } = new EconEvent<EventArgs>();
void Update()
{
UpdateEvent.Invoke(new EventArgs());
}
void FixedUpdate()
{
FixedUpdateEvent.Invoke(new EventArgs());
}
}
But the implementation doesn't seem to matter - none of the scripts that I have (and have used elsewhere in the project) seem to work suddenly (I've been doing some refactoring, so that's likely the impetus of this problem). I'm sure there's a workaround, but it's by no means as simple as you seem to suggest.
Answer by voidhope · Aug 27, 2018 at 03:34 PM
I met the same problem when I tried to attach PlayerController.cs to a game project. The VS debug errors analysis indicates PlayerController this name is kinda an exiting class or function. After I changed the cs name it became fine.maybe you can try this way.
Answer by teamasterln · Oct 03, 2018 at 12:37 PM
I had same problem. Deleting TextMeshPRo completly from project and than adding it again helped me
Answer by goodcompany54 · Jan 10, 2019 at 03:50 PM
Same Problem too often 1.Created & Named new script using Visual Studio 2017. Didn't rename it or anything else. 1. Tried to attach script to game Object/ Any Object. 2. Got then and gets now "Can't add script behaviour tmp CoroutineTween. The script needs to derive from monoBehavior" 3. I usually get around this problem by creating a new script and a new name, but not this time.
Defeated but not gone!