I have a native abstract uclass called Grenade with an UCapsuleComponent defined as a UPROPERTY.
UPROPERTY ( VisibleDefaultsOnly, BlueprintReadOnly, Category = Mesh )
UCapsuleComponent* Collision;
Inside the constructor I initialized it like this:
this->Collision = objectInitializer.CreateDefaultSubobject<UCapsuleComponent>(
this, TEXT("Collision"));
this->Collision->SetNotifyRigidBodyCollision(true);
this->Collision->SetCollisionProfileName(TEXT("Projectile"));
this->Collision->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
this->Collision->SetCollisionObjectType(COLLISION_PROJECTILE);
this->Collision->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
this->Collision->bReturnMaterialOnMove = true;
this->RootComponent = this->Collision;
It works just fine. I’m able to throw the grenade and detonate it inside the game. Due to a few issues with UCapsuleComponent we decided to replace it with an USphereComponent. Unfortunately, the game crash upon changing the object type to USphereComponent.
UPROPERTY ( VisibleDefaultsOnly, BlueprintReadOnly, Category = Mesh )
USphereComponent* Collision;
And inside the constructor:
this->Collision = objectInitializer.CreateDefaultSubobject<USphereComponent>(
this, TEXT("Collision"));
this->Collision->SetNotifyRigidBodyCollision(true);
this->Collision->SetCollisionProfileName(TEXT("Projectile"));
this->Collision->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
this->Collision->SetCollisionObjectType(COLLISION_PROJECTILE);
this->Collision->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
this->Collision->bReturnMaterialOnMove = true;
this->RootComponent = this->Collision;
The details panel inside the blueprint class won’t show anything which in my estimation indicates it has not been initialized:
If I add this to OnConstruction in addition to the code in constructor of the class it works inside the game (though still the details panel is empty):
this->Collision = NewObject<USphereComponent>(
this, TEXT("Collision"));
this->Collision->SetNotifyRigidBodyCollision(true);
this->Collision->SetCollisionProfileName(TEXT("Projectile"));
this->Collision->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
this->Collision->SetCollisionObjectType(COLLISION_PROJECTILE);
this->Collision->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
this->Collision->bReturnMaterialOnMove = true;
I suppose the blueprint class caches the constructor somewhere, so I created another blueprint. The first time I open the blueprint the Details panel shows the properties for the collision component. If I run the game and crash it it won’t show anything any more. I tested this on both Linux/Clang and Windows/VC++. I even tried renaming Collision to Collision2 or removing the original blueprints class from the project. None of that works.