❔ Deleting something from a canvas.
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?
12 Replies
read the error.
GetComponent<UIElement>()
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.
ah I thought it's unity sorry
you just cast
just cast
this
to that typeI've tried that and it gave me the same error as in the first screenshot.
.Remove((UIElement) this)
is this what yiu tried.Exactly.
then I need more context
how is that bullet added, what is that bullet made up of, etc.
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?
Might as well show you the full class:
there, you're adding the rectangle into the canvas children list
that's what you have to remove too
Yep, noticed that as soon as I hit send. 🤦
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.