❔ Deleting something from a canvas.

S(Storm (they/them)12/11/2022
How do I remove an entity from a canvas? I've figured out, that there is a "canvas.Children.Remove()" method, but the input it wants is confusing me. Anyone have an idea of how to proceed from here?
Image
AAntonC12/11/2022
read the error. GetComponent<UIElement>()
S(Storm (they/them)12/11/2022
I might be really thick, but this is what you meant, right? I've not come up against the GetComponent# before, so I'm not exactly sure how to use it.
Image
AAntonC12/11/2022
ah I thought it's unity sorry
AAntonC12/11/2022
you just cast
AAntonC12/11/2022
just cast this to that type
S(Storm (they/them)12/11/2022
I've tried that and it gave me the same error as in the first screenshot.
AAntonC12/11/2022
.Remove((UIElement) this)
AAntonC12/11/2022
is this what yiu tried.
S(Storm (they/them)12/11/2022
Exactly.
AAntonC12/11/2022
then I need more context
AAntonC12/11/2022
how is that bullet added, what is that bullet made up of, etc.
S(Storm (they/them)12/11/2022
A Bullet is a DynamicObject, which is an Entity. When an Entity is created, it is added to the canvas as you can see in this screenshot. It is also an IRemovable, from which I am trying to implement the DeleteItem() method. Is that what you meant?
Image
S(Storm (they/them)12/11/2022
Might as well show you the full class:
Image
AAntonC12/11/2022
there, you're adding the rectangle into the canvas children list
AAntonC12/11/2022
that's what you have to remove too
S(Storm (they/them)12/11/2022
Yep, noticed that as soon as I hit send. 🤦
AAccord12/12/2022
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.