#IEffect not being removed from List

1 messages · Page 1 of 1 (latest)

bitter meteor
#

Hello, so i am using Odin - and i have a list of Effects that use IEffect.

The issue is an IEffect isnt being removed from a IEffect List

So, been following the videos of GitAmend using Generic Interfaces, Clean Targeting systems.
Everything was going fine, stuff gets damaged and all that.
Changed the Classes to structs, made the IEffect Factories - The factories create a struct to the target - target does apply on the struct with itself (an IDamagable),

IEffect DmgEffect applies to a IDamagable, Adds to a list, performs Damage, cancels it self and is removed from the list.
IEffect DmgOverTime does the same - but when the timer is stopped, calling the OnCompleted Action with itself, it isnt removed from the list.

Now this could be me misunderstanding how structs interact with everything but i thought to ask and try to learn.
Because from my perspective, its a Struct being made, assigned to a list, the struct's method is called, and via the logic it should cancels it self - and via the Monobehaviour should be removed from a list.
But it isnt.

Code

InstantDMG, works - it applies, it does DMG, it removes itself.
https://pastebin.com/eTkLJJse

OverTimeDMG, works until the removal process, it remains there.
https://pastebin.com/VxzYH8qU

Dmg Tester, far as i can tell, it works, prints the dmg it taken, tells me whats in the list, etc etc.
https://pastebin.com/DbieCmaT

Ability, where the IDamagable gets the effect from.
https://pastebin.com/0J3GVCP3

IEffect, interface + struct factory
https://pastebin.com/R1E6iMX3

Videos
https://www.youtube.com/watch?v=L0cXb-ettK4
https://www.youtube.com/watch?v=aZanRrhBg-8&t=417s

mossy pawn
#

where's the code that should be removing it from the list?

tribal mason
#

first of all your values are always boxed so there's no point making them structs (which i think is the main problem here), you might as well make them classes

#

it looks like you're relying on Remove which compares the removed item each one in the list, but the over time effect modifies itself in its CleanUp so it no longer matches the one in the list

#

because struct comparisons by default compare all members

#

you can't call a method on the boxed struct without copying it, i think you're expecting reference type behaviour there but it's a value

mossy pawn
#

ah ok yeah found it. them being structs and having different equality semantics than expected is probably the cause as mentioned above

bitter meteor
# mossy pawn where's the code that should be removing it from the list?

Sorry i should of emphasised that, I know you found it but for future onlookers its in Damage Tester.
And right, i see - so them being structs and the Timer in Cleanup.

Thank you, and thank you @tribal mason for the input.

Regarding the:

your values are always boxed so there's no point making them structs
Where would i find more information on this, to get a better understanding

mossy pawn
#

it's a pretty specific term, googling "c# boxing" should give some resources

tribal mason
#

taking a glance at the C# docs and i'm not sure it shows this case in the examples, but storing a struct in a variable/field of interface type will always box it

bitter meteor
#

For note, i did invoke the OnCompleted Action in cancel, and that did remove it from the list.
i did make it structs because in the video they went from classes to structs, with a brief mention that Heap Alloc is lowered. My intent was just to try and follow along to ensure i understand the system before breaking it to rework it.

C# Boxing, alright, thanks! If i dont see a ring and a bell with classes punching i'll be sad.

tribal mason
#

that seems like an oversight in the video, i'm pretty sure their version would cause unintended boxing too

mellow furnace
mossy pawn
#

since boxing applies both to storing as an interface and as storing as object