Resize Collision Component in Blueprint (c++ inherited)


I’ve a Projectile C++ class which has these Collision properties:


The problem is that when I create a new Blueprint-Derived class from that class, I can’t resize my Collision Component.
I really really really need to resize that collision sphere, since in my game there are going to be many kinds of projectiles.

The CollisionComponent is declared in this way in the Projectile.h

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Projectile, meta = (AllowPrivateAccess = "true"))
	USphereComponent* CollisionComp;

I thought that setting BlueprintReadWrite would have solved this issue, but no luck.

Any tip?

Use EditAnywhere or EditDefaultsOnly instead of VisibleAnywhere.

Already tried that one, it doesn’t work

It could be caused by RootComponent = CollisionComponent. When you place an Actor of the class in the editor the Location/Rotation/Scale you set in the details panel are actually Location/Rotation/Scale of the RootComponent (I think), same goes for dynamically spawned instances. What you should do instead is use a dummy SceneComponent (CreateDefaultSubobject, then RootComponent = SceneComponent). Then Create your CollisionComponent as you’ve shown above but replace the last line with CollisionComponent->AttachTo(SceneComponent) (or RootComponent if you’ve already assigned it). This should not only allow you to do what you want but it will also be much more flexible since it’s going to allow you to both independently set Location/Rotation/Scale on the CollisionComponent and any other Components attached to RootComponent but also to set Location/Rotation/Scale “globally” for the Actor through the RootComponents Location/Rotation/Scale.

Please correct me if I’m wrong.

If I do like you suggested


This event doesn’t fire anymore

// When the projectile hits something
	MovementComp->OnProjectileStop.AddDynamic(this, &AProjectile::OnImpact);

Well, that’s kinda strange. I just tested almost all combinations of UPROPERTY() specifiers… and it just works on my side.
I have super simple test class:

// .h file
class SPHERETEST_API ASphereActor : public AActor

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Projectile, meta = (AllowPrivateAccess = "true"))
    class USphereComponent* CollisionComp;

    ASphereActor(const FObjectInitializer& ObjInitializer);

// .cpp file
ASphereActor::ASphereActor(const FObjectInitializer& ObjInitializer)
    CollisionComp = ObjInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("Collision"));
    RootComponent = CollisionComp;

Looks like VisibleAnywhere and BlueprintReadonly is the best choice, so I was a bit wrong.