Destroying a gameobject when the players score reaches a certain number

So I’ve created a maze game where the player has to collect items. Once all items are collected, the game ends and takes the player back to the main menu. I want to change this to expand the level. I want to be able to destroy one of the walls of the maze and extend the level in that direction when the player collected the desired amount of objects. I created a Blueprint class called BP_SecretController, and attached the desired wall to it and put it in the game world. Where the C++ code used to load the main menu, I instead have created code to try to destroy the object, but it is not working. I’m not sure that I am referencing the object correctly. In the game world, the object is called BP_SecretController2. Below is the code:


 if (Score >= 12.0f)


UPROPERTY(EditAnywhere, Category = Building)
    UStaticMeshComponent* BP_SecretController2;

You need to make sure your GameMode actually knows about the BP_SecretController2, and it’s not an empty reference.

It’s easier for you to create an actor that owns this component and store the actor’s reference or access its component and store it.

For this, you can, at some point of your code, access it using ActorIterator to search for the created actor.…_Faster_Search

You can, also, try spawning this actor from inside your GameMode class, and then storing the resulting actorreference or access it’s component and store it.

So, make sure the reference is not empty by finding a way to store the actor’s reference before calling it.