Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Nocturneon · Jul 14, 2016 at 08:59 PM · c#errorclassmonobehaviour

"The class named is not derived from MonoBehaviour or ScriptableObject!", although class is derived from MonoBehaviour

I keep getting the error "The class named 'OldManSounds' is not derived from MonoBehaviour or ScriptableObject!". I have researched this, and seen that the solution is usually to add ": MonoBehaviour" to the class declaration. However, my class declaration is as follows:

 public class OldManSounds : MonoBehaviour {

yet I still receive the error, even though I'm stating that it's derived from MonoBehaviour. How can I fix this?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vintar · Jul 14, 2016 at 09:09 PM 0
Share

It would help to see the entire script. I assume you have "using UnityEditor" at the top.

avatar image Nocturneon vintar · Jul 14, 2016 at 09:12 PM 0
Share

Here's the full script:

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 public class Old$$anonymous$$anSounds : $$anonymous$$onoBehaviour {
     AudioSource audio1; AudioSource audio2;
     public AudioSource[] aSources;
 
     void Start() 
     {    
         aSources = GetComponents<AudioSource>();
         audio1 = aSources[0];
         audio2 = aSources[1];
     }
 
     void OnCollisionEnter(Collision collision) {
         foreach (ContactPoint contact in collision.contacts) {
             Debug.DrawRay(contact.point, contact.normal, Color.white);
         }
         if (collision.relativeVelocity.magnitude > 2)
             audio1.Play();
         if (collision.relativeVelocity.magnitude < 2)
             audio2.Play();
 
     }
 }
avatar image CesarNascimento Nocturneon · Jul 14, 2016 at 09:14 PM 0
Share

Where are you getting this error? On the console? Can you upload a picture with the error in question?

Show more comments
avatar image Bunny83 · Jul 14, 2016 at 09:36 PM 0
Share

Are you sure that you don't have other real errors? If there are errors in one of your scripts non of the scripts will compile / work until you fix all errors. Errors have a red icon while warnings are yellow.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ISeidingerReflekt · Dec 17, 2019 at 09:56 AM

If you are using assembly definition (.asmdef) files: Make sure the script is not limited to the editor platform

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by vintar · Jul 14, 2016 at 09:21 PM

Its as I said in the comment above. Remove the line "using UnityEditor" and all will be well ;)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nocturneon · Jul 14, 2016 at 09:28 PM 0
Share

All is not well. I still receive the same error.

avatar image abeldantas Nocturneon · Feb 22, 2017 at 01:36 PM 1
Share

Is the script in a folder called 'Editor"? That can also trigger this warning

avatar image OtsegoDoom abeldantas · Apr 20, 2018 at 02:21 PM 0
Share

I encountered the same issue with an old project I revisited. Turns out I had my script in editor folder. $$anonymous$$oving it out of there cleared the error. Thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

No Monobehaviour scripts in files 1 Answer

You are trying to create a MonoBehaviour using the new keyword. This is not allowed 2 Answers

C# Conception - Hide inherited members and functions 1 Answer

Problem with attaching scripts to objects 1 Answer

Object reference not set to an instance of an object in c# class. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges