Destroy actor, who is existing in level, Accessed none trying to read property error

Hey guys,

I’m trying to do some stuff with the widget.

My target is to delete existing actor from the level.

Sphere is my existing object in the level.

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.

How can I get a reference to this object?

Thx in advance!

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.

SphereObject is an object reference from the blueprint, which constains the defaultSceneRoot and the staticMesh - Sphere

Is there any easy way to get reference to the sphere, which exists in my level? How should I make it?

The bright side is that I’m not going to change Level, that’s why I’m asking about getting the reference to my SphereObject

This will work but it will get you in trouble sooner than later, mark my words :wink:

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.

Good luck.

It was even more simple than I thought, this solved the problem :