x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Spawn an Actor without collision

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);
 }
Product Version: UE 4.12
Tags:
more ▼

asked Aug 28 '16 at 10:11 AM in C++ Programming

avatar image

Snoat
15 1 2 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hello Snoat,

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)

//SETUP SPHERE

 pDetectionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("FishSphere"));
 pDetectionSphere->SetupAttachment(RootComponent);
 pDetectionSphere->SetSphereRadius(DetectionRadius);
 pDetectionSphere->OnComponentBeginOverlap.AddDynamic(this, &ANpcFish::OnOverlapBegin);
 pDetectionSphere->bGenerateOverlapEvents = true;

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: https://docs.unrealengine.com/latest/INT/Gameplay/ClassCreation/CodeOnly/

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!

more ▼

answered Aug 29 '16 at 07:45 PM

avatar image

rth2
21 2 2 3

avatar image Snoat Aug 29 '16 at 09:15 PM

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 :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Could you try

 CollisionComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);

and see if it changes anything?

more ▼

answered Aug 29 '16 at 11:21 AM

avatar image

indygoof
830 26 15 41

avatar image Snoat Aug 29 '16 at 06:40 PM

Thx, but doesn't work for me. I think there is a preset that defines the collision: For making this actor I did this: 1. Create actor class 2. Added a box CollisionComp = CreateDefaultSubobject(TEXT("CubeComp")); 3. 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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question