Hi there,
I’ve derived Sphere Component into a new class with which I aim to use for checking what a character can see. For this, I want the sphere to basically float in front of the player and generate overlap events - when an actor enters, it is considered visible.
Here’s my header code (I’m assuming the C++ in this case is irrelevant!):
UCLASS(meta = (BlueprintSpawnableComponent))
class ROGUELIKE_API UCharacterVisionSphere : public USphereComponent
{
GENERATED_UCLASS_BODY()
//Pointers to actors that are within vision
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Character)
TArray<AActor*> VisibleActors;
/** called when something overlaps the predefined boundaries of the item */
UFUNCTION()
void OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
bool IsActorVisible(AActor*);
};
The problem is that, when attached to one of my characters, it always, always, stays in one place. I’ve added 4 characters around the map, each with a “vision sphere” attached, and all of the spheres seem to stack in the same spot right in the middle of the map.
This works with a normal sphere - when I attach it to the character blueprint and set it to moveable, it follows the character as shown:
The sphere in front of the character is the standard sphere. The sphere on the right, embedded in the floor, is my derived version. All of the characters in the map that have a vision sphere, the resulting sphere ends up in that location. In the picture, there are in fact roughly 5 stacked on top of each other.
Is there any good reason for this? I’ve been unable to find a good solution at all. Here’s what the blueprint editor looks like:
Any help would be extremely appreciated…