How to destroy an added component?

For example I’m grabbing a Drag Controls component that gets added by Drop Listener and want to remove it

Original Post on Discord

by user 103054507105067008

either this.destroy() on the component (or theComponent.destroy()) or GameObject.destroy(theComponent)

If its networked use GameObject.destroySynced(...)

I tried this, it reports that console.log but the drag component still works in the scene

        if( != null)
        //remove drag component
        if (

by user 103054507105067008

Ok that sounds like a bug - I’ll try in a minute

Any chance there is another DragControls component in the scene? When I destroy it here it stops working as expected

(tried destroying before awake, in awake, in start and onEndDrag and those all worked as expected :thinking: )

Ill try with the droplistener

Oh hey looking at your code: you need to call

Currently you destroy whatever component is running this code

aha, I’ll try that

by user 103054507105067008

That works

by user 103054507105067008