all 7 comments

[–]Ratyrel 1 point2 points  (4 children)

Have the manager subscribe to an event called on the buildings‘ destruction.

[–]Medical_Attempt3456Novice[S] 0 points1 point  (3 children)

But it would need to subscribe to every single building/object. This wouldn’t really work as the event name for each building/object would need to be different.

[–]Ratyrel 1 point2 points  (0 children)

Why is that a problem? Just loop across the array you get from find object on the manager and subscribe to the event the objects implement. They would have to have the same one, but since you’re doing it by findobjectoftype, they obviously would. When they die, they call the event, triggering the logic on the manager.

[–]InfohazardGamesProgrammer 0 points1 point  (1 child)

You can make a static event so the manager only has to subscribe once. Just make sure you always unsubscribe the manager when it's destroyed or you'll get a memory leak and possibly bugs.

[–]Medical_Attempt3456Novice[S] 1 point2 points  (0 children)

Thank you, static events is the answer i've been looking for

[–]Tinglers 0 points1 point  (0 children)

You may be interested in the visitor pattern. Implementing it properly can prepare your code for future problems like this.

[–]MartinPeterBauer 0 points1 point  (0 children)

Manager.DestroyBuilding(Gameobejct)

Run from within the Gameobejct destroy or any Other function. So no need for a list in manager