Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Herman-Tulleken · Nov 20, 2009 at 12:27 PM · mono-behaviour

Why are my MonoBehaviour methods not called?

I have the following very simple code; the script is attached to my game character:

class NeuralNetController extends MonoBehaviour {

 function Start()
 {
     Debug.Log("Start called");        
 }

 virtual function Update()
 {
     Debug.Log("Update called");
 }

}

but it does not work - that is, neither method gets called. When I remove the class syntax, like this:

function Start() { Debug.Log("Start called"); }

virtual function Update() { Debug.Log("Update called"); }

then it works fine. Do I have the syntax wrong? Or should I extend from another class? Or is there something else going on?

Just as an experiment, I also added the virtual keywords to the function declaration of the first example; that too, did not work.

(If you are wondering why I don't simply use the second method - since it works - it is because I actually need to extend from another class that extends from MonoBehaviour. I just took out the irrelevant detail.)

Comment
Add comment · Show 3
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 Ehren · Nov 20, 2009 at 11:01 PM 0
Share

Do you have any other code in the script file? Any variables, functions, or other classes? That "irrelevant detail" might actually be causing things to break down. :)

avatar image Herman-Tulleken · Nov 22, 2009 at 06:27 PM 0
Share

The answer below was it (of course, I also made sure that the problem occurred with the irrelevant stuff removed ;-)

avatar image Tetrad · Mar 05, 2010 at 06:11 PM 0
Share

Why did you make your Update function virtual? It doesn't need to be for Unity to call it.

1 Reply

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Brian-Kehrer · Nov 21, 2009 at 01:36 AM

Most likely the script is not named exactly 'NeuralNetController', which it must be if you extend the monobehaviour. The class name and script file name must match, if you use C#, it will tell you this. I dropped your script into unity and renamed it appropriately, and it worked perfectly.

The javascript compiler is unfortunately very prone to letting you make unintended mistakes. For this reason alone, I highly recommend using C#. It's syntax is more strict, and for that reason, you will end up making fewer mistakes from simple typos, as the compiler will gently warn you, instead of silently doing something unintended.

using UnityEngine; using System.Collections;

public class NeuralNetController : MonoBehaviour{

void Start(){ Debug.Log("Start called");
}

public virtual void Update(){ Debug.Log("Update called"); }

}

Comment
Add comment · Show 1 · 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 Herman-Tulleken · Nov 22, 2009 at 06:26 PM 0
Share

Thanks $$anonymous$$, that was it. Can't believe it was that simple!

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

One of my scripts has no check-box next to it in Inspector 2 Answers

How to import the object from server to unity 2 Answers

How to use intelisence in mono (in order to get all the contents of other script file) 1 Answer

monobehaviour script accessing problem causes error 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