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
2
Question by diddykonga · Mar 20, 2012 at 03:45 AM · inheritancemonobehaviourstartunity 3.5

Class isnt having Start called

Hello, my problem is that i have a class that inherits from a base class that inherits from monobehaviour, and when i override start inside of the child class, it never gets called.

Im using Unity 3.5 release and im not sure if that might be a problem with the build.

Thanks for the quick response her is the child objects code

 using UnityEngine;
 using System.Collections;

 public class Grenadier : Character {

 void Start () {
     CharacterCombo = ComboManager.GetCombo("Grenadier");
     CharacterCombo.Init(this);
     
     Name = "Grenadier";
     
     Speed = 3.5f;
     
     Defense = 4;
     ForceResistance = 16;
     
     Jump = 24;
     MaxJumps = 1;
     
     GameManager manager = GameManager.GetGameManager();
     manager.ItemSpawn("DazeBomb"); // Testing if Start is even being called :L
 }
 }

Character (Base Class) doesnt have any code for Start, whats really wierd is my code works in the editor just not when i export it.

Looked into the output_log file, after building the windows build and it did seem to print out what i believe is an error

 ArgumentException: Encoding name 'Windows-1252' not supported

 Parameter name: name
 at System.Text.Encoding.GetEncoding (System.String name) [0x00000] in <filename unknown>:0 

 at System.Xml.XmlInputStream.Initialize (System.IO.Stream stream) [0x00000] in <filename unknown>:0 

 at System.Xml.XmlInputStream..ctor (System.IO.Stream stream) [0x00000] in <filename unknown>:0 

 at (wrapper remoting-invoke-with-check) System.Xml.XmlInputStream:.ctor (System.IO.Stream)

 at System.Xml.XmlStreamReader..ctor (System.IO.Stream input) [0x00000] in <filename unknown>:0 

 at (wrapper remoting-invoke-with-check) System.Xml.XmlStreamReader:.ctor (System.IO.Stream)

 at System.Xml.XmlTextReader..ctor (System.IO.Stream input) [0x00000] in <filename unknown>:0 

 at System.Xml.Serialization.XmlSerializer.Deserialize (System.IO.Stream stream) [0x00000] in <filename unknown>:0 

 at ComboManager.GetCombo (System.String _name) [0x00088] in C:\Users\Admin\Desktop\Battle Brawl\Assets\Battle Assets\Scripts\Managers\ComboManager.cs:25 

 at Grenadier.Start () [0x00000] in C:\Users\Admin\Desktop\Battle Brawl\Assets\Battle Assets\Scripts\CharacterArchetypes\Grenadier.cs:7 
 
 (Filename: C Line: 0)
Comment
Add comment · Show 4
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 kromenak · Mar 20, 2012 at 04:34 AM 1
Share

Are you using C#? I'm not sure how it works with Unityscript, but in C# you need to mark the Start function in the base class as virtual and the Start function in the child class as override.

Then make sure you call base.Start() if you want the base class' functionality.

avatar image Berenger · Mar 20, 2012 at 04:54 AM 1
Share

Or you don't declare Start in the BaseClass at all, the overriding isn't necessary (or even correct) then.

diddykonga, don't forget that Start isn't called on inactive objects.

avatar image Bunny83 · Mar 20, 2012 at 05:00 AM 0
Share

I have to agree with @kromenak and @Berenger.

A simplification of your code would be helpful to understand and reproduce your problem.

avatar image diddykonga · Mar 20, 2012 at 06:45 AM 0
Share

*Added code to question

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Meltdown · Mar 20, 2012 at 07:01 AM

Try marking your Start method in the base class as virtual. Then put the override keyword in front of your start method in your Grenadier class...

i.e

in the Character class...

 protected virtual void Start()
 {
   // Do any Character base class initialisation here
 }
 
 then in the Grenadier class...
 
 protected override void Start()
 {
   // Do any Grenadier specific class initialisation here
 }
Comment
Add comment · Show 13 · 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 diddykonga · Mar 20, 2012 at 07:07 AM 0
Share

Tried this and i still get the same result, Start is not being called in the child class :(

avatar image Meltdown · Mar 20, 2012 at 08:02 AM 0
Share

Do you have the child class script attached to an active object that exists in your scene?

avatar image diddykonga · Mar 20, 2012 at 08:20 AM 0
Share

Its attached to a prefab, which is in turn instantiated so yes

avatar image Berenger · Mar 20, 2012 at 03:34 PM 0
Share

is the component Grenadier enabled ?

avatar image diddykonga · Mar 20, 2012 at 03:57 PM 0
Share

Yes, its not that the component isn't working at all because all of the code that is in the the base class is getting run, just nothing in the child class that inherits from it is

Show more comments

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

7 People are following this question.

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

Related Questions

Previously functional script now mysteriously does not invoke Start or Update methods 2 Answers

What is the signature of Awake() and Start() 1 Answer

C# Conception - Hide inherited members and functions 1 Answer

Execution order when Start is declared with IEnumerator return (as a Coroutine) 1 Answer

Start() is called on Play and on Stop 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