One-time items/collectibles from breakable objects - How to best implement

This is more of a general game development question. In the game I’m working on, I plan to have several breakable objects. Some of these will spawn one of several items when broken. I want it to work so that once the player breaks these objects and their respective loot items are created AND collected, that the breakable object will no longer spawn those collectible loot items again. This is to prevent the player from being able to farm items easily.

My first thought is that this would be done with a Global Variable structure, setting up the events so that when the object is broken and a global boolean variable associated with the collection of its contents is false, it will spawn whatever item. If that item is collected, you would set the global variable to true, never being set to false again regardless of whether the player changes scenes and comes back to the current scene.

However, with a lot of breakable objects in a game, this method feels like it could get messy with a lot of global variables to keep track of in the structure. But it’s the only way I can think of to make this work. Is there a “best practice” way of accomplishing these one-time collectibles from breakable objects? I’m open to any advice or tips at all to make this process as smooth as possible.

A second question as well, if I may. Using the same breakable object-item spawn example above, if instead you wanted the item to not spawn from the breakable object again for a set period of time (say, 5 minutes), what would be the best way to accomplish this with a timer? I assume I would use an object timer and appropriate object variables for the breakable object, but if the player breaks several breakable objects in the 5 minute example, are there then going to be several object timers running at the same time? If so, how would this affect the performance of a game?

Sorry for the long message, but I figured it was better to ask both questions here rather than creating two separate topics. Thanks in advance for any and all advice!!!

You could put the object names in an array similar to this example. You pick a random number based on the number of items in the array, create an object from that element and then remove it from the array.

Now, in your case you could add the randomly picked object’s name to another array and then every say 5 minutes remove an element form that array using the same technique and then add it back to the main list.

Another approach might be to add some bias to the picking of objects. Maybe have 3 groups; common, medium and rare. You could then pick a random number from say 1 to 100. If the number is from 1 to 70 then pick a random common item. If it’s 71 to 90 pick a meduim item. If it’s between 91 to 100 choose a rare item.

1 Like

Good information as always. Thank you! I think the randomizing might be the best option for me. Maybe a 2/10 chance of a common item, a 1/10 chance of others. Or something to that effect. I’ll have to figure out the odds once I implement it. This would essentially almost prevent farming the items, since the chances are low enough but if there are enough breakable objects that you break, you’re bound to at least get something out of them. Thanks again!

1 Like