c# - All references in list point to 'this' -


running c# .net 3.5 code in unity producing weird issue

class x {     static list<x> _l = new list<x>();      public x()     {         _l.add(this);         debug.log(_l.count(x=>x==this));     } } 

for each object create, counter increases 1... gives? of course snippet bigger application core issue simple; when adding list constructor , retrieving said list should give 1 result , 1 result only, no matter how object created; right?

if more code required i'll add i'm hoping has experienced before. i'm not sure version of mono unity uses think it's 2.0.

unity may auto-implementing object.equals method , equality operator overrides may causing == check not checking reference equality other criteria.

removing inheritance monobehaviour (or unityengine.object), implementing own operator overrides, or changing expression _l.count(x => object.referenceequals(x, this) may resolve it.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -