- Home /
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)
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.
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.
I have to agree with @kromenak and @Berenger.
A simplification of your code would be helpful to understand and reproduce your problem.
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
}
Tried this and i still get the same result, Start is not being called in the child class :(
Do you have the child class script attached to an active object that exists in your scene?
Its attached to a prefab, which is in turn instantiated so yes
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613065327im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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