Collecting all of a certain type of item pickup to make something happen?

Hey again, so recently I’ve been trying to create a setup wherein if the player collects all of the special pickups (in this case, Purple Star Gems) within the level, then a reward will be spawned from a invisible item spawner.

’Purple Star Gem’ item pickup blueprint:

Reward spawn point blueprint:

At least that’s the idea anyway, in practice though, I haven’t been able to get it to work properly with a couple of problems that need to be addressed.

#1.) The first problem is that the special item pickups are no longer being destroyed upon being touched. This isn’t a collision issue as the pickup counter still ticks upwards upon collision. I’ve also noticed that the sound effect that’s suppose to play before the actor is destroyed is also not working anymore as well. I’ve tried a variety of different things to see if I could get the Destroy Actor node to properly destroy the special item pickup but nothing I’ve tried so far has worked.

#2.) The item respawner isn’t working as intended as the reward that’s suppose to appear when the player collects the right amount of the special pickup items isn’t appearing. The item spawner shouldn’t be affected by the special item pickups not being destroyed, so I’m not sure what’s going on here.

#3.) And finally, something’s screwy going on with the way that the number of special item pickups are being counted when the player touches one. Normally the print string number should be going up sequentially (i.e. 1, 2, 3 4, 5, 6, etc.], but instead I’m getting some strange numbers:

print_item_count

As you can see if this screenshot, instead of the numbers appearing in sequential order, I’m getting seemingly random numbers [55, 52, 51, 50, 49, 36, 37, 52]. The numbers are increasing as my player touches the special item pickup, albeit in a rather chaotic manner.

Can anyone help me out with this?

Hi! Few Suggestions: avoid casting too much.
Casts are expensive. Use tags instead: Add tag to the actors like: pickup item and things like that and then instead of 'get all of class 'you can do ‘get all with tag’…same instead of cast you can do ‘actor has tag’ and in the case you must access the class you cast only if hast tag succeeds :slight_smile:

for the failing respawn check in the dropdown option for collision handling. change to ALWAYS SPAWN.

Hope it helps :slight_smile:

1 Like

Okay, so after taking another look at my blueprints, I think I might have identified a possible suspect for why my setup isn’t working. The problem I’m fairly certain lies with the cast to the reward spawn point within the Purple Star Gem blueprint. The reason I think this is because I’ve noticed that everything within the blueprint before the cast works, while everything that doesn’t is after the cast.

It could be a coincidence but I doubt it, especially since I’m having a similar problem on another blueprint wherein everything after the cast is non-functional.

Unfortunately, despite identifying what’s very likely causing the problem, I don’t know how to go fixing it. I mean, if I get rid of the cast to the reward spawn point blueprint, then how do I communicate to it to play out the rest of the code?

Not sure on your setup but GetOwner() doesn’t look like it will return a reference to the Reward Spawn Point here so your cast will fail. You can easily check with a printstring on the cast fail and check what getowner gives you.

If this is the case, it looks like you need a reference to the spawnpoint… maybe using GetActorsOfClass or by setting a variable beforehand. Depends on your needs.

IMHO the cost of the casts here are negligible.

1 Like

Okay, that worked, well sorta anyways. The purple star gems are disappearing when collected as intended and the reward item is now spawning but the problem is that the reward is spawning after only one purple star gem is collected and not all of them. Additionally there’s also an oddity where if the player collects more than one purple star gem at the same time it will result in multiple rewards being spawned on top one another. Any other star gems that weren’t collected at a same time as the first one touched won’t spawn a reward.

I’m also now getting error messages within the Message Log:

Any idea on what the heck is going on? Here’s the revised Purple Star Gem blueprint as reference:

The reward spawn point blueprint hasn’t been altered in any way since I created this topic so the blueprint in my initial post is still up to date.

To address the errors, do a “isvalid” node on the return from the get actors of class. Although its weird this fires an error if you have this an actor of this class in your level.

It sounds like you need logic in your playercontroller to check how many gems collected, etc. I would set up a function there like AddGem(GemColorType) and then let the PC handle the counting and reward spawn rather than having that logic in the Gem. ie: if PurpleGemCount > RewardPurpleGemCount branch to spawn reward at RewardSpawnPoint.

1 Like

I finally managed to get the whole setup to work, as per your suggestion I removed the logic for keeping track of the number of purple star gems collected from the purple star gem blueprint itself.

However, rather than your suggestion of putting it in the Player Controller, I instead decided to put the purple star gem counter within the reward spawn blueprint. I also made a change to the Get All Actors of Class node, as it was set to get all actors of the Purple Star Gem class upon Event BeginPlay, which doesn’t make any sense as they need to be spawned in via breaking the container first. I’m not sure why it was set to that but I changed it to get all actors of the Purple Star Gem spawn point class instead.

With all of these modifications made, the whole thing works although I did end up using Event Tick to get it to work. I realize that its a bad idea to over rely on Event Tick but I couldn’t think of an alternate way of making this work. I’m not sure if there’s an alternative method but if anyone has any suggestions then I’m all ears. Otherwise though everything seems to be in working order, so thanks to everyone who helped me out!

Rather than on tick you should create a custom event (or function) that is called when you pick up a gem. (right click> add custom event in the spawnpoint bp). Then move the logic you have under the tick to that new custom event. You can add input nodes to the event if you need to pass data to it rather than setting the variables with the Gem Actor.

1 Like

Thanks, that worked.