c# inheritance

I got a base class where a list is declared. An object of the child class is created. In its load function it will call a function in the base class that populates the list. All good so far, the debug log tells me how many object that were added. When the player collides with a certain object the base class is called to go to the next item in the list. Here is where the problem arises. The debug log now tells the list is empty. If I do a debug check from the child class update is says I got the same number of items that was loaded to begin with.

Thing is if I create an object of another child class (same base class) this works fine and both of the child classes are identical.

Anyone have any clue what’s going on here?

Edit1: All the above mention scripts are placed on a game object in the game scene. I just tried removing the first child script and the second child script started working as intended… Not sure what that means though.

Edit2: OK, guess work here… When the child class asks the base class to populate the list it’s actually the child class list that is filled. But when the player collides with a certain object and the base class is called to go the next item in the list it actually checks its own list which is empty. But that doesn’t explain why it would work if there is only 1 child class script placed in the scene?

Edit3: Fixed. When the player collides with a certain object the child class is called which in turn calls the base class to go to the next item in the list.

I am still a bit baffled about this so if anyone could explain what happens here that would be awesome. I understand what I did wrong, but why would it work if there was only 1 child script in the scene?

Im pretty sure that unity always calls the most derived class functions first when its doing its own triggered calls (even start etc i think).
see post 2 here http://answers.unity3d.com/questions/1889/does-unity-support-multiple-inheritance
This might be part of your problem.

Any chance you can show a sample of each of the classes involved.

It could have to do with virtual/override/new/base and hiding.

hehe thread from 2009, im guessing its dead, i only replied coz it came up on a search …:slight_smile: