Hey All,
Edit: Issue’s have been resolved! see last few posts!
Let me begin by saying that i’ve been reading the forum & awnserhub on overlap events for almost a week now, really sorry to add yet another thread on the subject, i just cant for the life of me figure out what the hell is wrong with my setup. I either get UE4 to crash entirely (like, the editor even) or i get something that doesnt work or show up, and im reaching a point where i just wanna say f*ck it and give up on UE4 development all together, which obviously isnt good.
In short, what im trying to do is this, i have a USceneComponent derived class, which is intended to be a ‘grabber’ for a VR game, in that class i try to create a USphereComponent so that later down the line i can check for overlap events between that and things i want my player to be able to grab. The problem is that my created USphereComponent seems broken if i create it with NewObject, or i crash UE4 if i try create my USphereComponent in the class construct or a BeginPlay via the CreateDefaultSubObject function (which i dont even want, i want to create it at runtime when a function is called, but ive been trying things i see others do successfully)
Im coming too the above conclusion that “my USphereComponent seems broken” because (when created with NewObject at runtime) while i am able to log its position, and can verify that yes, it is changing as i move my controller, when i run the console command ‘show Collision’ it doesn’t actually show my USphereComponent on the controller? (i’ve also verified that the radius i set is actually set, and that the coordinates match those of my controller) and thus not fire the overlap events (since theres nothing overlapping?)
So yea, really puzzled here, since im still pretty new too the engine im sure its just some small thing im overlooking, but after sifting trough dozens of similar threads/questions, watching a few youtubes on the subject, i still cant figure out what im missing here. Below some thoughts i keep looping trough
- I guess maybe i need to fire some function on the USphereComponent to ‘create the shape’?
- Something is off with the coordinates, even though looking at log output seems to suggest it positions fine?
- Maybe it does actually have the USphereComponent at the right position, it has the right size and everything, it just doesn’t show when i run the console command ‘show Collision’ because whatever, and the overlap events dont fire because of something else?
I am a 100% sure that the objects im trying to get overlap events from (StaticMeshes) support that by the way, all the proper checkboxes are set, and i can get overlap events with them trough other routes.
Finally, the important bit, a trimmed version of my code:
UCustVR_MyGrabber.h
//...
UENUM(BlueprintType)
enum class UCustVR_EGrabberShapes : uint8 // The different Grab shapes
{
BOX UMETA(DisplayName = " Box "),
SPHERE UMETA(DisplayName = " Sphere "),
CAPSULE UMETA(DisplayName = " Capsule ")
};
//...
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class CUSTOMVRPLUGIN_API UCustVR_MyGrabber : public USceneComponent
{
GENERATED_BODY()
public:
//...
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR")
bool EnableGrabber = true; // Enable the Grabber
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "VR")
UCustVR_EGrabberShapes Grabber_Shape = UCustVR_EGrabberShapes::SPHERE; // The shape of the Grabber
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR")
int Grabber_Shape_Radius = 16; // The Radius of the Grabber, used for Sphere & Capsule shapes
//...
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR")
FVector Grabber_PositionOffset = FVector::ZeroVector;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR")
FRotator Grabber_AngleOffset = FRotator::ZeroRotator;
// Setup the grabbers
UFUNCTION(BlueprintCallable, Category = "VR")
void SetupGrabbers();
// Delegate functions that'll be called during begin & end of overlap
UFUNCTION()
void Grabber_OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void Grabber_OnEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
//...
private:
//...
USphereComponent* Grabber_USphereComponent;
//...
};
UCustVR_MyGrabber.cpp
//...
void UCustVR_MyGrabber::SetupGrabbers() {
if(EnableGrabber) {
switch (Grabber_Shape) {
case UCustVR_EGrabberShapes::BOX:
//...
break;
case UCustVR_EGrabberShapes::SPHERE:
Grabber_USphereComponent = NewObject<USphereComponent>(this, FName("GrabberComponent"));
Grabber_USphereComponent->SetSphereRadius(Grabber_Shape_Radius);
Grabber_USphereComponent->SetWorldLocation(GetOwner()->GetActorLocation() + Grabber_PositionOffset);
Grabber_USphereComponent->SetWorldRotation(GetOwner()->GetActorRotation() + Grabber_AngleOffset);
Grabber_USphereComponent->AttachToComponent(GetAttachParent(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, NAME_None);
Grabber_USphereComponent->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
Grabber_USphereComponent->BodyInstance.SetResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
Grabber_USphereComponent->OnComponentBeginOverlap.AddDynamic(this, &UCustVR_MyGrabber::Grabber_OnBeginOverlap);
Grabber_USphereComponent->OnComponentEndOverlap.AddDynamic(this, &UCustVR_MyGrabber::Grabber_OnEndOverlap);
UE_LOG(LogTemp, Warning, TEXT("Created Grabber Sphere!?!??"));
if (Grabber_USphereComponent) {
UE_LOG(LogTemp, Warning, TEXT("Location: %s"), *Grabber_USphereComponent->GetComponentLocation().ToString());
UE_LOG(LogTemp, Warning, TEXT("Radius: %f | %f"), Grabber_USphereComponent->GetScaledSphereRadius(), Grabber_USphereComponent->GetUnscaledSphereRadius());
}
break;
case UCustVR_EGrabberShapes::CAPSULE:
//...
break;
}
}
//...
}
//...
void UCustVR_MyGrabber::Grabber_OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
//...
UE_LOG(LogTemp, Warning, TEXT("Grabber OnBeginOverlap Fired!!?!"));
}
void UCustVR_MyGrabber::Grabber_OnEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
//...
UE_LOG(LogTemp, Warning, TEXT("Grabber OnEndOverlap Fired!!?!"));
}
If anybody has any clue at all to what i might be doing wrong, im open to any and all input, i just cant see how to resolve this or further debug it