C
C#2y ago
Clara

❔ 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
Anton
Anton2y ago
read the error. GetComponent<UIElement>()
Clara
ClaraOP2y ago
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.
Anton
Anton2y ago
ah I thought it's unity sorry you just cast just cast this to that type
Clara
ClaraOP2y ago
I've tried that and it gave me the same error as in the first screenshot.
Anton
Anton2y ago
.Remove((UIElement) this) is this what yiu tried.
Clara
ClaraOP2y ago
Exactly.
Anton
Anton2y ago
then I need more context how is that bullet added, what is that bullet made up of, etc.
Clara
ClaraOP2y ago
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?
Clara
ClaraOP2y ago
Might as well show you the full class:
Anton
Anton2y ago
there, you're adding the rectangle into the canvas children list that's what you have to remove too
Clara
ClaraOP2y ago
Yep, noticed that as soon as I hit send. 🤦
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server