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"

Can't trigger callback USphereComponent collision

New to UE4 and C++. I am trying to get some basic collision/proximity code working. I can see the ProxSphere in blueprint editor and the sphere is visible in the editing viewport. When I run the scene it logs out the "NPC INIT" message from the constructor, but I can't seem to be able to get the Prox function to run when player character enters the sphere.

NPC.h

 // Fill out your copyright notice in the Description page of Project Settings.

 #pragma once

 #include "GameFramework/Character.h"
 #include "NPC.generated.h"

 UCLASS()
 class GOLDENEGG_API ANPC : public ACharacter
 {
     GENERATED_BODY()

 pubic:
     // The sphere that the player can collide with to get item
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
     USphereComponent* ProxSphere;
 

    ANPC();
 
     UFUNCTION()
     void Prox(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
 
 };


NPC.cpp

 // Fill out your copyright notice in the Description page of Project Settings.

 #include "GoldenEgg.h"
 #include "NPC.h"
 #include "Avatar.h"
 #include "MyHUD.h"

 // Sets default values
 ANPC::ANPC()
 {
     UE_LOG(LogTemp, Warning, TEXT("NPC INIT"));
     ProxSphere = CreateDefaultSubobject<USphereComponent>(TEXT("Proximity Sphere"));
     ProxSphere->InitSphereRadius(120.0f);
     ProxSphere->AttachParent = RootComponent;
     ProxSphere->OnComponentBeginOverlap.AddDynamic(this, &ANPC::Prox);
 }

 void ANPC::Prox(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
 {  
     UE_LOG(LogTemp, Warning, TEXT("In Prox"));

 }
Product Version: UE 4.11
Tags:
more ▼

asked Apr 22 '16 at 01:18 PM in Bug Reports

avatar image

systmShok
8 1 2 5

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

1 answer: sort voted first

Hey SystmShok-

Your setup appears correct, I had the same issue using OnComponentBeginOverlap and have entered a bug report (UE-29879) for investigation. As a workaround, you should be able to use OnActorBeginOverlap() instead, or set up the component overlap through blueprints with an event dispatcher / custom event.

Cheers

Doug Wilson

more ▼

answered Apr 25 '16 at 03:26 PM

(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