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. 

Cannot Change SphereCollision's Radius

I tried to changed SphereCollision's Radius in several place:

Character.cpp

 InteractorComponent = CreateDefaultSubobject<UInteractorComponent>(TEXT("InteractorComponent"));
 InteractorComponent->SetupAttachment(RootComponent);
 InteractorComponent->InitSphereRadius(500.0f);
 InteractorComponent->OnComponentBeginOverlap.AddDynamic(this, &APGCharacterBase::OnInteractorBeginOverlap);

alt text The debug line do show the radius is 500.0f. However, at in-game, the radius does not reflect to 500.0f. OnComponentBeginOverlap does not fire until I'm at radius 32.0f.

Though, I have found out to force the Component to recognize 500.0f as the collision radius, I have to do the OnComponentBeginOverlap in Blueprint. Is there anyway I can it without going through Blueprint?

Product Version: UE 4.22
Tags:
untitled.png (226.0 kB)
more ▼

asked Apr 30 '19 at 09:22 AM in C++ Programming

avatar image

XynanXDB
3 1 1 4

avatar image XynanXDB Apr 30 '19 at 03:30 PM

Edit: I have moved the function binding into PostInitializeComponents and it still does not work. More so, after trying to figure out what's going, the OnComponentBeginOverlap at the Blueprint side started failing.

avatar image Lardo Deepdelver May 01 '19 at 07:12 AM

to be honest your initial code looks correct

I tested it myself with a normal sphere component and it works as you would expect

.h: // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

 #pragma once
 
 #include "CoreMinimal.h"
 #include "AnswerHubAnswersCharacter.h"
 #include "CharacterWithSphere.generated.h"
 
 class USphereComponent;
 
 UCLASS(config = Game)
 class ACharacterWithSphere : public AAnswerHubAnswersCharacter
 {
     GENERATED_BODY()
 
 public:
     ACharacterWithSphere();
 
     void BeginPlay() override; 
 protected:
     UFUNCTION()
     void OnInteractorBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
         UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
         const FHitResult& SweepResult);
 
     UPROPERTY(VisibleAnywhere)
     USphereComponent* SphereComponent;
 };

.cpp:

 #include "CharacterWithSphere.h"
 #include "Components/SphereComponent.h"
 
 ACharacterWithSphere::ACharacterWithSphere()
 {
     SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("USphereComponent"));
     SphereComponent->SetupAttachment(RootComponent);
     SphereComponent->InitSphereRadius(500.0f);
 }
 
 void ACharacterWithSphere::BeginPlay()
 {
     Super::BeginPlay();
     SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &ACharacterWithSphere::OnInteractorBeginOverlap);
 }
 
 void ACharacterWithSphere::OnInteractorBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, 
     int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
 {
     UE_LOG(LogTemp, Warning, TEXT("So Overlappy!"));
 }

The only thing i changed is move the registration to the overlap into the BeginPlay had strange behavior in the past when I had that somewhere else.

So either your UInteractorComponent is doing something strange, or the radius is changed somewhere else.

avatar image XynanXDB May 01 '19 at 07:21 AM

I did try to move the function bindings into BeginPlay() but I remembered I was still seeing that problem and I didn't set the radius anywhere except that place. Probably I have to rebuild the project tmr.

Another question is, putting the function bindings in PostInitializeComponents is still dangerous?

avatar image Lardo Deepdelver May 01 '19 at 01:54 PM

if you look at the ActorLifecycle it should be fine, I personally still prefer BeginPlay(), since it's exactly the same behavior for spawned and loaded actors

avatar image XynanXDB May 01 '19 at 02:11 PM

I'll try it tmr, will comment here whether if it's working or not.

avatar image XynanXDB May 06 '19 at 08:08 AM

It seems the problem is solved by rebuilding, weird, but thanks for helping.

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

0 answers: sort voted first
Be the first one to answer this question
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