I read much posts about removing collision from Actors, but none of them worked for me. I’m trying to have a Box, where you can walk through, but I’m stucking at removing the collision. My current constructor code is:
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Add Box
CollisionComp = CreateDefaultSubobject<UBoxComponent>(TEXT("CubeComp"));
// Set as root component
RootComponent = CollisionComp;
this->SetActorEnableCollision(false);
}
Thx, but doesn’t work for me. I think there is a preset that defines the collision:
For making this actor I did this:
Create actor class
Added a box
CollisionComp = CreateDefaultSubobject(TEXT(“CubeComp”));
Tryed to remove collision the constructor.
So actually what I’m trying to do is a Trigger: If a player enters a certain area, a function should being be called. Am I doing wrong like this? Is there maybe another better way to do this?
From your one comment it sounds like you are trying to make a trigger but not a hard collision correct? This is how I have been making trigger effects (my example will use a sphere component because I can pull it from code that I know works)
ANpcFish is the class. This makes it so that characters can walk through the sphere (which is invisible) and trigger it if they also allow overlap events (which is just a check box in a collision component). Then you define the functionality you want in the OnOverlapBegin(…)
The definition looks like this :
UFUNCTION()
void ANpcFish::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
// your functionality when something overlaps this; this example checks to see if the player overlapped with
//my sphere. If so remove the sphere component because I only want this to trigger once.
//if collision was on the detection sphere
USphereComponent* pSphere = Cast<USphereComponent>(OverlappedComp);
//returns null if other actor is not player fish
APlayerFish* pPlayer = Cast<APlayerFish>(OtherActor);
//player hit our detection sphere, no longer need the sphere. Sets to nullptr automatically.
if (pPlayer && pSphere)
{
pSphere->DestroyComponent();
}
}
This also needs to be in your header file like this
UFUNCTION()
void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
The UFUNCTIION() above both of these is an important macro. It has to be there. This is a link to a really quick tutorial in the documentation using c++ only: CPP Only Example | Unreal Engine 5.1 Documentation
Hopefully this helps! Remember that this sets the component to generate overlap events but those will only trigger with other actors/objects that also generate overlap events! Hopefully the wall o’ text isn’t so bad!
Thank you so much for your so detailed explaination, now everything works! I tryed to get it working for some days but still stucked somewhere. And also thx for telling me the thing with UFUNCTION(), without you I never would have figured it out