Hi, I apparently changed something in my castle blueprint, and now enemy soldiers cannot find it anymore when they are searching for the closest enemy actor in their behavior tree. I use
in my FindClosestTargetService, which is used in the Behavior Tree of the soldiers. It does not return the castle as a potential candidate, which I confirmed through logging.My castle class inherits from APawn and some other class, see:
UCLASS()
class CASTLEFIGHT_API AGEPawnTest : public APawn, public IAbilitySystemInterface
{
GENERATED_BODY()
...
So the APawn::StaticClass() call should be correct.The soldiers can find each other and soldiers are also based on class AGEPawnTest, so this does not seem to be the issue. The collision settings should be correct as well, the castle’s box collision component is set to world static, block all. The soldier’s capsule component is set to World Dynamic and blocks everything except a custom channel which is only used by the ground. Generate Overlap Events is checked for the soldier and castle blueprint.What could cause the reason?
Here is the collision setting of my castle’s box collision component
Interesting,but this is not the case here and also the Overlap finds the barrack producing the respective soldier, so that cannot be the issue. By the way, just if anyone wonders, I also double checked that the castle is within acquisition range by computing the distance by hand.
First thing I did was to check the Behavior Tree, where I saw that the TargetActor was set to None (previously, before fiddling with the base c++ class, everything was working fine, just for reference). Indeed, I check whether the target actor exists and is outside of the attack range. If this condition is met, a move in range task is executed. However, the TargetActor is null/none, which is caused by the SphereOverlapActor for some reason ignoring the castle.
To be clear: This behavior tree is working as intended with another type of building (which has a different base class) and enemy soldiers (which share the same base class with the castle).
Ok, by comparing the castle to another building that the soldier is sensing correctly/that creates an overlap event, I noticed that the mesh of that building had its collision turned on. This was not the case for the castle. I now turned the collision on (BlockAllDynamic) for the mesh of the castle and suddenly it creates an overlap event, i.e. the soldier is approach it correctly (albeit the fog of war is not revealed, but that is another issue). Do collision boxes not generate overlap events in the SphereOverlapActor function? I’d like to understand the cause here. The block collision settings for the mesh’s are identical to the box collision’s.
I solved it. For some reason, the AcquisitionObjectTypes was filled with WorldDynamic, which initially my new castle class did not use as object type. The object type previously was World static, because I chose the preset “Block all”, which uses World static.
However, I never touched the AcquisitionObjectTypes object and did not find any assignment to AcquisitionObjectTypes using Visual Studio. Neither do I find an assignment in the blueprint editor. I do not know why this array even had one entry. It was declared as
/\*\* Types of actors to filter for when trying to find targets in the acquisition radius. \*/`UPROPERTY(BlueprintReadWrite, Category = "RTS")`TArray<TEnumAsByte<EObjectTypeQuery>> AcquisitionObjectTypes;
Really strange, maybe someday I find out where it gets its element from (it has exactly one).