When I was trying to delete it without Is Valid function I had this error : “Accessed none trying…”
When I used this IsValid function the error is down but nothing is happening when the button is pressed.
Where did you take the SphereObject variable from? If you just create a reference in the widget, it will be empty until you assign it some value. That reference is in no way connected to the object in the level (even though they are sharing the name).
I’m assuming here that the SphereObject you want is the one you dragged into the level from the Content Browser.
You generally would not want to access Level Blueprint objects from within a widget because when you change levels, these objects stop existing, making your widget useless.
If you must use it this way, you’d have to approach it from the other direction.
Once your level is loaded and the widget created, push the valid objects into the widget. So, in your LevelBlueprint, you can obtain a reference to one of the accessible classes like PlayerController, GameInstance or GameMode and, providing you store a widget reference there, get the widget’s reference and set the object’s reference inside the widget.
Also, look into Event Dispatchers, they make communication with the LevelBlueprint less of a hassle.
This will work but it will get you in trouble sooner than later, mark my words
Put 5 randomly placed actors in the level and try to destroy the 3rd one from the left. Now you do not know which one is which. The above is the embodiment of sloppy coding.