Checking if overlapping Actors are specific amount and type of Actors

I hope you guys can help me, atm I am trying to build a blueprint prototype for a gameidea contest of ours. Because of a possible game that might spawn out of this, it’s a c++ project, but I do the prototyping in Blueprints, so this is a blueprints question. I have tried quite a lot but I fail to understand the logic needed, on paper it’s straight forward and should work well, it’s just that as my first project I don’t know all blueprint notes and I have run into a stone wall with this. - also its been a long workday of staring into the same screen, might have something today with that.
I am trying to archive this:

On open craft menu (press “c” key – set up and working) check which actors “collection box” (collision box component part of the character) is overlapping with. Then: if its 2 Twigs set bool lighter to true, if its 2 branches and 30 twigs set bool shelter true, if its 4 branches and 10 twigs set bool fire true.

Then (this part is already set up and working) the craft menu which has already been opened has three buttons for lighter, fire and shelter and if the bool or the object is true it can be placed otherwise the game prints debug “you don’t have the resources”.

So basically I am stuck at the check of the overlapping actors, comparing them to the amounts and stetting the booleans accordingly.
I have attached the current setup (yes I am aware atm they all get set to true – thats what I am trying to change :wink: )

(After uploading I realized that a) this is the CharacterBP and b) The Hud Ref is connected because I copied this to take the screenshot, it works so no need to point that out )

Additional Info:
I know that the overlapping actors part works, I have - in c++ - a setup which I created where the player picks up power ups that change attributes. So I know it works.
My 2 Blueprints, BP_Twig and BP_Branch, which I am placing in the level to be used for crafting are both children of a c++ crafting pickups class. That class at the moment only adds a mesh, the children blueprints are untouched (other then the static being added.).

I would highly appreciate the help and if possible posted pictures of the solution, as I do hope to finish this in time. Thank you in advance!

If you can confirm that the overlapping actors array is properly being populated. I recommend building a map with the results, the key being the actor class and the value being the count.

Since I am completely oblivious to the blueprint nodes available to you (I solely use C++) and you seem savvy enough with blueprints and probably have a basic understanding of pseudo-code, so I’ll go ahead and give you a rundown.

TMap<AActor, int32> ActorCountMap;

foreach AActor in OverlappingActors
    ActorCountMap.FindOrAdd(Actor.GetClass) + 1 // FindOrAdd returns a value reference associated with the key. Add one to it.

At this point you can manipulate the buckets however you want. Do you have 30 sticks?

if (ActorCountMap.Find(StickClass) >= 30) Do Something;

Thanks for the reply, yes I do know the basics of code. Can you maybe help me with the actual syntax, I can’t find any documentation about the for each loop and also don’t quite understand how you get the OverlappingActors in. Following Problem:

How do I actually populate the TMap with the overlapping actors, the TArray that check overlapping actors is in a different functon and not connected so I assume I have to first have a TArray in this function?

	TArray<AActor*> CraftingActors;
	CollectionBox->GetOverlappingActors(CraftingActors);

I know this works - its the same setup as for my pickups. However how do I populate the TMap with the result? I can’t find any documentation regarding it.

As for the Blueprints, that will all work now thanks to your help. I will have this function be called via blueprints when i need it and can use the booleans set in it in the Hud Button logic. So all thats missing is the actual population of the TMap and the logic which set the bool true.
Thanks again.

I was under the impression that you were doing this in blueprints.

You are on the right track. (As always, any provided code is not guaranteed to work - get back to me if it doesn’t)

TArray<AActor*> CraftingActors;
CollectionBox->GetOverlappingActors(CraftingActors);

// Depending on how you use this it may be stored as a variable in your header instead of as a local variable.
TMap<UClass*, int32> CraftingActorBuckets;

CraftingActorBuckets.Empty();

for (AActor* Actor : CraftingActors)
{
    ++(CraftingActorBuckets.FindOrAdd(Actor->GetClass()));
}

To find out whether you have enough sticks:

if (CraftingActorBuckets.FindOrAdd(AStickActor::StaticClass()) > NumberOfRequiredSticks)
{
    DoSomething();
}

The code above implies that your (for example) stick actor blueprint inherits from a native class AStickActor. If you are using C++ and you need to deal with blueprint classes it is generally a good idea to make your blueprint actor extend from a custom AActor instead of directly from AActor. That way you can do operations like the one above.

You don’t have to use the method above. The point I am trying to get at (if you are not keeping track of your item count somewhere) is to create buckets, fill them, them get the bucket you want and count how many are in there to get your final result.

Yeah sorry for the confusion, it was a Blueprint question but as it turns out populating a TMap in Blueprints is not possible – or so I think.Seeing how I want to learn c++ and this is already a c++ project it all works out well!
Thanks to your help I got it working!
However (and this is more for future reference for other people) I did have to change the code a bit for it to work. I don’t know why but it wouldn’t add anything to the Bucket with your code example.
I got around it like this:

// set all crafting bool to default
	SetCraftShelter(false);
	SetCraftLighter(false);
	SetCraftFire(false);

	//Get all overlapping Actor and build a Map
	TArray<AActor*> CraftingActors;
	CollectionBox->GetOverlappingActors(CraftingActors);

	TMap<UClass*, int32> CraftingActorBuckets;
	CraftingActorBuckets.Empty();

	for (AActor* Actor : CraftingActors)
	{
		// Check if Actor is a Branch
		if (Actor->IsA(ACraftIngredientBranch::StaticClass()))
		{
			// Adds a Branch
++(CraftingActorBuckets.FindOrAdd(ACraftIngredientBranch::StaticClass()));
		}
		// Check if Actor is Twig
		if (Actor->IsA(ACraftIngredientTwig::StaticClass()))
		{
			// Adds a Twig
	++(CraftingActorBuckets.FindOrAdd(ACraftIngredientTwig::StaticClass()));
		}
	}
 	// set if lighter can be crafted with overlapping actors
	if (CraftingActorBuckets.FindOrAdd(ACraftIngredientTwig::StaticClass()) >= 2)
	{
		SetCraftLighter(true);
	}

If I have any other items for crafting I will just add another if condition for those later on.
Thanks again!