Search Unity

What does this error mean exactly?

Discussion in 'Scripting' started by markhula, Feb 5, 2012.

Thread Status:
Not open for further replies.
  1. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hi all,

    Just started getting:

    The same field name is serialized multiple names in the class or it's parent class. This is not supported: Base(Boomerang) character1

    What I don't understand is that I haven't altered the boomerang or character1 class. It would be nice if it told me which field. What should I be looking for?????

    Cheers
     
  2. foxter888

    foxter888

    Joined:
    May 3, 2010
    Posts:
    530
    you need to show the code, since that error doesn't says enough it's pretty much saying that you have something repeated that it doesn't like.
     
  3. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I have a hard time believing that's actually the error. ;) Copy and paste from the Console; don't type the error!
     
    Bunny83 and idurvesh like this.
  4. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    :)
    It's rather a lot of code!, as I said nothing has been altered.
    Is it suggesting there is a conflict in boomerang and character1?; but these classes do not inherit from either....

    Cheers
     
    U7Games likes this.
  5. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    @Jessy,

    That is *exactly* the error as in the debug log window. I DID cut 'n' paste it from the open editor log!!! . lol!

    Cheers
     
  6. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    That's the worst error message I've seen out of UT, then. :-| We need to know how to reproduce this so a bug can be filed and it can be turned into English.
     
    idurvesh likes this.
  7. foxter888

    foxter888

    Joined:
    May 3, 2010
    Posts:
    530
    it's really hard to help if you can't post a code to go through.
     
  8. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    :)
    I am using 3.5.0f1 so that *might* be an issue. I can't post the boomerang and character1 code as they are very long. But as I said neither class is inherited from the other. I'm not even sure what problems (if any) the error actual causes.
    Just seemed strange and a bit too vague :)))

    Cheers
     
  9. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Length doesn't matter. Attach the files or a package.
     
  10. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    Seems like a bug in Unity. I got the error with my c# codes. But i try editing the codes and reverting back and the error is gone.
     
    emredesu and vald1412 like this.
  11. lancerfour

    lancerfour

    Joined:
    Feb 24, 2010
    Posts:
    24
    I just had a similar error:

    Looks like it happened because I defined a variable named "id" in both my District class and it's base class BoardObject. Removing the "id" field from the District class cleared the error.

    So, check that you don't have a same-named field declared in both your parent class and your inherited class.

    @markhula's case: You probably have a field called character1 in both your Boomerang class and its base class.
     
  12. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hi,

    Nope neither is inherited from the other!!!. Anyway, the 'error' has now disappeared some upgrading Unity and *no* alteration to the code. So assume a nice bug :)

    Cheers
     
  13. JanWosnitza

    JanWosnitza

    Joined:
    Jun 23, 2012
    Posts:
    6
    The error happened to me when I tried to have a private field in a class, which also exists in one of it's base classes as private:

    public class A : MonoBehaviour
    {
    private int wiredMessageFireField;
    }

    public class B : A
    {
    private int wiredMessageFireField;
    }

    and there you have it. Hope it may help you all and let become Unity the best tool out there ;)
     
    sajadswork, Awayn and U7Games like this.
  14. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I am getting that error with this...
    Code (csharp):
    1.  
    2.     public float[] tweenTimeScale;
    3.  
    and I have not applied it to anything, it is just a random var. set to public, private or protected.


    ???



    the full code.
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5.  
    6. public class TweenChainGUI : BaseDemoGUI
    7. {
    8.     // we have 4 cubes setup
    9.     public Transform[] cubes;
    10.     public float[] tweenTimeScale;
    11.    
    12.     void Start()
    13.     {
    14.         // create a TweenConfig that we will use on all 4 cubes
    15.         var config = new TweenConfig()
    16.             .setEaseType( EaseType.QuadIn ) // set the ease type for the tweens
    17.             .materialColor( Color.magenta ) // tween the material color to magenta
    18.             .eulerAngles( new Vector3( 0, 360, 0 ) ) // do a 360 rotation
    19.             .position( new Vector3( 2, 8, 0 ), true ) // relative position tween so it will be start from the current location
    20.             .setIterations( 2, LoopType.PingPong ); // 2 iterations with a PingPong loop so we go out and back 
    21.        
    22.         // create the chain and set it to have 2 iterations
    23.         var chain = new TweenChain().setIterations( 2 );
    24.        
    25.         // add a completion handler for the chain
    26.         chain.setOnCompleteHandler( c => Debug.Log( "chain complete" ) );
    27.  
    28.         // create a Tween for each cube and it to the chain
    29.         foreach( var cube in cubes )
    30.         {
    31.             var tween = new Tween( cube, 0.5f, config );
    32.             chain.append( tween );
    33.             print("cube " + cube);
    34.         }
    35.        
    36.        
    37.         _tween = chain;
    38.     }
    39. }
    40.  
     
  15. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    You probably have tweenTimeScale defined in BaseDemoGUI as well.
     
    KingTlol likes this.
  16. NewAlpha

    NewAlpha

    Joined:
    Aug 12, 2012
    Posts:
    15
    I'm getting this error as well.

    I have an Enemy class which two classes inherit from.

    It gives this error for all of the variables (both public and private) within Enemy class.

    This is my Enemy class :

    Code (csharp):
    1. public class Enemy : MonoBehaviour {
    2.  
    3.     public float MinSpeed;
    4.     public float MaxSpeed;
    5.     public float CurrentSpeed;
    6.     private float x, y, z;
    7.     public int Live;
    8.     public string enemyColor;
    9.    
    10.     public void SetPositionAndSpeed ()
    11.     {
    12.         CurrentSpeed = Random.Range(MinSpeed , MaxSpeed);
    13.         x = Random.Range(-6f, 6f);
    14.         y = 7.0f;
    15.         z = 0.0f;
    16.        
    17.         transform.position = new Vector3(x, y, z);
    18.     }
    19. }
    20.  
    This is one of my subclasses (the other one is the same as this one):
    Code (csharp):
    1. public class GreenEnemy : Enemy {
    2.     void Start ()
    3.     {
    4.         Live = 0;
    5.         enemyColor = "Green";
    6.         SetPositionAndSpeed();
    7.  
    8.     }
    9.    
    10.     // Update is called once per frame
    11.     void Update ()
    12.     {
    13.         if (FadeTime.FT)
    14.         {
    15.             float AmoutToMove = CurrentSpeed * Time.deltaTime;
    16.             transform.Translate (Vector3.down * AmoutToMove);
    17.        
    18.             if (transform.position.y <= -5f)
    19.             {
    20.                 SetPositionAndSpeed();
    21.             }
    22.         }
    23.     }
    24. }
     
  17. cspeer504

    cspeer504

    Joined:
    Sep 26, 2012
    Posts:
    11
    FYI - This recently happened to me today twice.

    The first time, I had declared a variable with the same name in both the parent and child classes. This was just a copy/paste mistake when moving the variable to the parent class. I didn't cut/paste so it was still defined in the child.

    The Second time it happened I couldn't explain it. It explicitly told me that my child class had defined m_bIsJumping unnecessarily as it was already defined in the parent class. After triple checking, this was not the case. Just to be sure, I double checked all of the variables in the child and parent class and they all checked out ok. However, before I got the error I was just setting the get/set accessor "Jumping" as virtual and overriding it in the child class. So I figured A) Something was wrong with that override or B) the compiler was bugged/confused/wrong. The override checked out, so I resorted to the compiler being the problem. So I shut down Unity and MonoDevelop and opened them back on and the error went away.

    Long story short: If variable definitions all look "ok" to you, shut Unity and Monodevelop down and run those applications again. Once you re-load your project, try running it and see if this error goes away.

    P.S. - This happened to me on the Unity 4.1.5f1 and MonoDevelop 2.8.2.
     
  18. smp4903

    smp4903

    Joined:
    Nov 6, 2013
    Posts:
    1
    I seem to be able to trigger this error:

    Code (csharp):
    1. The same field name is serialized multiple names in the class or it's parent class. This is not supported: Base(Session) level
    By calling this in update:

    Code (csharp):
    1. if(!transform.collider.enabled) StartCoroutine (ResetColliderPrecaution ());
    2.  
    Here's the method:

    Code (csharp):
    1.    
    2.  // used as a precaution
    3.     IEnumerator ResetColliderPrecaution ()
    4.     {
    5.         yield return new WaitForSeconds(5f);
    6.         transform.collider.enabled = true;
    7.         StartCoroutine (ResetColliderPrecaution ());
    8.     }
    9.  
    I'm guessing the recusive call is the issue?
     
  19. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    You can't use coroutines in Update as far as I know.

    Also, what are you trying to achieve with that method? I'm not used to C#, but in Unityscript that wouldn't do much I think.
     
    Last edited: Nov 6, 2013
  20. Heitor Almeida Click

    Heitor Almeida Click

    Joined:
    Jan 15, 2014
    Posts:
    1
    Thank you very much, cspeer504. The bug also happened to me and I fixed it by closing both programs. I was quite confused, since this is a rare error and even grammatically it makes little sense.
     
  21. Patrick234

    Patrick234

    Joined:
    Jun 25, 2014
    Posts:
    88

    This error is still in unity and extremely annoying! i been searching this out and turns out its a limitation of C#?!

    http://stackoverflow.com/questions/...a-member-variable-field-in-a-c-sharp-subclass
     
  22. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    AlteregoGames01 and Bunny83 like this.
  23. Patrick234

    Patrick234

    Joined:
    Jun 25, 2014
    Posts:
    88
    "virtual property of A and override it in B." went with that.

    Appears C# handles abstraction a bit differently from other languages i was used to. I thought " New " did that. Instead i need "Virtual and Override"!

    In terms of methods i wouldve want to layer them, and then use base.method() to call chain down to the lowest abstract class. With " New" it failed, it appear to somehow ignore base.method() in certain cases, and in other cases it looked like it worked. However, when i changed it all to Virtual and Override, it did exactly what i needed it todo.
     
  24. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    Hell no! That is a bad advice. Protected fields ruin everything what C# and OOP stands for.
    Private fields of different classes have nothing in common. It's clearly unity serialization bug, and why does serializer crawl to my privates is beyond my comprehension.
    Unity team, please explain what's going on!
    .
     
    Last edited: Oct 31, 2014
  25. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Um - what? Protected fields ruin everything C# and OOP stand for? Based on what evidence? What does C# "stand for" in the first place? And yes - private fields of different classes have nothing in common. Private fields in classes that are related to each other because of inheritance could be a different story.

    Also - without know exactly what Unity's serialization process is doing - I can see where it might visit your private fields because a private field can be serialized if it's annotated with SerializeField.
     
  26. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    It's called encapsulation. It's a big topic actually (wiki) It doesn't affect protected properties.
    Anyway, I understand when serializer can touch private fields, but they at least should be attributed. And I understand why serializer can't distinguish owner of serialized member in some cases, as I can see in prefab format.
    I managed to lose wrong serialized data, I'm not sure how but if
    didn't help, try to change serialization mode Edit>Project settings>Editor>Asset Serialization
    Looks like it force re-serialized everything and the error is gone.
     
  27. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    I understand what encapsulation is. On the very wiki page you linked one of the bullet points is inheritance - which, you could argue, protected fields fall under the umbrella of. If protected fields "break OOP" then why does every major OOP language include it as a feature?

    If you have interesting points to make then please do it without being condescending and inflammatory.
     
  28. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    You just called the right clean solution "wrong pattern" and advised to make a kludge instead of eliminating the error. I'm not a teacher of any kind, I will not make a quick OOP lecture course here. But the point is that the ability to do something doesn't mean it's a good solution. Again I don't force anyone code style or anything, I'm just irritated by such confident phrase and such "solution".
     
  29. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    The right clean solution can be right and clean all day long but if it trips up Unity's serializer then I guess it doesn't really matter at the end of the day, does it? Even if it is a bug, folks need a way to get their work done in the meantime.

    I apologize for being so irritating to you - but ultimately one of us provided a solution and one of us didn't. If you don't like it, then don't use it and go bark up someone else's tree.
     
  30. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    I have nothing to answer on such self confidence.
    For future readers:
    It's NOT a wrong pattern
    It's NOT a C# limitation.
    It's NOT a Unity limitation (thank god!)
    It's just a spontaneous bug from which we can get rid of. Still it's a sad situation, I hope this bug will be fixed.
     
    virtualjay, Novack, Tortuap and 2 others like this.
  31. Darker

    Darker

    Joined:
    Mar 24, 2014
    Posts:
    2
    Still not fixed? I'm using Unity 4.5.5

    And I still get it for hiding inherited members (even though I use the new keyword) :

    The same field name is serialized multiple times in the class or it's parent class. This is not supported: Base(Ant) def
     
    BryanO likes this.
  32. getyour411

    getyour411

    Joined:
    Oct 14, 2012
    Posts:
    6
    Go in MonoDevelop (or VS) / Solution / scripts (assuming you have all in that hierarchy) and in the upper right search on the name; that, for me, found the instance of the variables I accidentally had repeated in base/extended
     
  33. ajdrew81

    ajdrew81

    Joined:
    Mar 9, 2015
    Posts:
    11
    Thanks much. Had this error and this fixed it right up! Thanks again!
     
  34. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,825
    Smae error here:

    Code (csharp):
    1.  
    2.  
    3. public class DoorController : MonoBehaviour{
    4.      public string doorOpenFX="DOORLATCH";
    5.      public string doorCloseFX="DOORLATCH";
    6.      public int SPEED = 2;
    7. }
    8.  
    9. public class SmallDoorController : DoorController
    10. {
    11.    public void Start()
    12.    {
    13.          SPEED = 1;
    14.          doorOpenFX = "smallDoorOpen";
    15.          doorCloseFX = "smallDoorClose";
    16.    }
    17. }
    18.  
    19.  
    upload_2015-6-17_3-35-50.png

    This error seems to make no sense
     
    Last edited: Jun 17, 2015
  35. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Using your script on a gameobject in my project doesn't produce any errors. There must be something else going on in your project.
     
  36. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,825
    the errors are very intermittent. sometimes they appear in the console for about 2 seconds then completely disappear. Sometimes they stay there until I restart the project.
     
  37. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    I'm getting this right now. I've just refactored something from one class to a parent/child class. For some (but not all) fields promoted to the new parent class I get this error on compilation. Some of them appear more than once. One of the fields being flagged as an issue isn't marked for serialization.

    My guess is that it's because I've got an instance of the now-child class in my scene, and the scene was saved prior to the refactoring. I suspect that the error is being emitted during deserialization as multiple values are now being found for those fields - the old one stored in the scene data, and a default one coming from the not-yet-serialized fields in the new parent class.

    Edit:
    I saved the scene, closed and re-opened Unity and it's gone.
     
    Last edited: Jun 24, 2015
  38. zty

    zty

    Joined:
    Jul 7, 2015
    Posts:
    4
    Is there a bug somewhere? This is still happening in Unity5
     
  39. Nick-Eq

    Nick-Eq

    Joined:
    Jul 31, 2012
    Posts:
    2
    For what it's worth, I just saw this bug today in Unity 5.3.4f1. Saving, quitting Unity, and restarting made the error disappear. No change in my code required.
     
  40. Simon_says

    Simon_says

    Joined:
    Oct 19, 2013
    Posts:
    141
    This bug still exists in 5.3.5p7. The variables are both private in my base and child class, and even if I put the "new" keyword in the child class on that private variable(which is not needed since it's already private so no need for hiding it), I'm still getting this serialization error.
     
    Last edited: Jul 20, 2016
  41. nghiattran

    nghiattran

    Joined:
    Aug 27, 2016
    Posts:
    3
    The error means you declare 2 variables with the same name in base class and derived class and they all have [SerializeField] modifier. This make Unity confuse which one you actually want to serialize.

    I hope this help.
     
  42. robertwahler

    robertwahler

    Joined:
    Mar 6, 2013
    Posts:
    43
    Reusing the same private field name in a parent/child class causes the error intermittently. It happens to me without the [SerializeField] modifier. It must be a bug with Unity.
     
    elseforty and U7Games like this.
  43. Shinugami

    Shinugami

    Joined:
    Oct 17, 2012
    Posts:
    54
    I had the same problem with using "m_Name".
    So I had a look for all instances of "m_Name". There was only one script.cs that had such a data-member. * Note that there was only 1 instance and not multiple instances as the error states.
    One other script.cs instance had "m_Name_First" and "m_Name_Last" however that was the extent and neither of these are the same which means again: the error is inaccurate.

    // Error because:
    ScriptA.cs: Contains "m_Name"
    ScriptB.cs: Contains "m_Name_First", "m_Name_Last"

    I figure that the error does not distinguish between "_" underscores due to these being removed in the editor display and replaced with a space. The build would work perfectly but I would get an error message and the build would work anyway. If the code functions then it's not an error and therefore I believe the Unity 'logic conditions' that exist to declare whether or not there is an error, need to have some exceptions added so as to minimize wasted time when trying to fix an error that is actually not an error.

    For the sake of Unity diplomacy I renamed the single instance of "m_Name" to "m_Name_Spaceship" and the error disappeared.

    // Error vanished when culprit was renamed to:
    ScriptA.cs: Contains "m_Name_SpaceShip"
    ScriptB.cs: Contains "m_Name_First", "m_Name_Last"
     
    Last edited: Sep 25, 2016
  44. Hullabu

    Hullabu

    Joined:
    Oct 23, 2014
    Posts:
    18
    You will not believe it, but this bug still exists...
     
  45. anthonov

    anthonov

    Joined:
    Sep 24, 2015
    Posts:
    160
    same here,
    with protected field in base class, then new private in derived.
     
  46. atalantus

    atalantus

    Joined:
    Jan 17, 2016
    Posts:
    16
    Unity 2017.1.0f3

    I had the same exception:

    Code (CSharp):
    1. The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(MonoBehaviour) dodged
    My classes looked like this:
    Code (CSharp):
    1. public class KillerRabbitStart : KillerRabbitStart
    2. {
    3.     public bool dodged;
    4.     //other code
    5. }
    6.  
    7. public abstract class KillerRabbitStart : State
    8. {
    9.     public bool dodged;
    10. }
    Than I simply deleted the declaration in my KillerRabbitStart class.
    That solved the error.

    So the message made sense for me.
     
    unity_AkGames likes this.
  47. sketchygio

    sketchygio

    Joined:
    Nov 6, 2014
    Posts:
    31
    Similar thing happened to me today. Still not sure if it's a bug or not based on the previous discussions in this thread. I had two separate classes, Projectile and Explosion, each with a public 'damage' variable. I tweaked Explosion to inherit from Projectile and forgot to delete the damage variable declaration in Explosion. This caused me to get a vague error in the console:

    Code (CSharp):
    1. The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(MonoBehaviour) damage
    2. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

    Thing to note is that while it does list the name of the variable 'damage' and its type, it doesn't list the names of the offending classes 'Projectile' or 'Explosion', which led me on a bit of a wild goose chase (you can imagine how many classes might use a similar inherited damage variable). So yeah, not sure if this is working as intended or not, but it would be nice if console was a bit clearer on the error.
     
  48. Estecka

    Estecka

    Joined:
    Oct 11, 2013
    Posts:
    62
    There's definitely a bug where this error persists when it should be gone:
    As mentionned above, I eventually fixed it by restarting Unity, not by changing my code.
     
    plvs_games_ltd_dev likes this.
  49. Mister_Horrible

    Mister_Horrible

    Joined:
    Apr 12, 2015
    Posts:
    6
    I've seen this exact error
     
  50. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    Hi all,
    I was creating a class then I needed to have multiple entrie in a menu to create same object but with different names :p
    so I inherited from base class except for the field string/type. I used the new key word to make the intent of shadowing the base class field explicit.
    Code (CSharp):
    1. public new string type;
    when I try to create an object other then the base class I get the error which makes no sens to me, no syntax error etc...
    I tried:
    restart unity = same
    defining clone classes = not really proficient :/

    using a name space and adjusting the code as fellow, the error is gone.
    Code (CSharp):
    1.         public childClass()
    2.         {
    3.             base.type = "Prefix_NewName";
    4.         }
     
    Last edited: Jul 8, 2018
Thread Status:
Not open for further replies.