Applying force to dynamically created object

I’m attempting to spawn objects, place some force on them, and then when they fall below x, destroy them.

I’ve pulled some code from the following tutorial: Components and Collisions to get me started.

// Spawner
void AProjectileSpawner::SpawnOneItem()
{
    UWorld *w = GetWorld();
    APlayerCameraManager *cMgr = GetCameraManager();

    UClass *uc = AProjectile::StaticClass();
    FTransform t(cMgr->GetCameraRotation(), cMgr->GetCameraLocation());
    ESpawnActorCollisionHandlingMethod always;
    always = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;

    AProjectile *p = w->SpawnActorDeferred<AProjectile>(uc,
                                                        t,
                                                        NULL,
                                                        NULL,
                                                        always);

    p->ForwardForce = ForwardForce;
    p->UpwardForce = UpwardForce;
    UGameplayStatics::FinishSpawningActor(p, t);
}

// Spawnee
AProjectile::AProjectile()
{
#define SOBJ_ROOT TEXT("RootComponent")
#define SOBJ_MESH TEXT("Mesh")
#define PROFILE_NAME TEXT("PhysicsActor")
#define SPHR_DIR TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere")

    PrimaryActorTick.bCanEverTick = true;

    USphereComponent* sCmp = NULL;
    sCmp = CreateDefaultSubobject<USphereComponent>(SOBJ_ROOT);
    RootComponent = sCmp;
    sCmp->InitSphereRadius(1.0f);
    sCmp->SetCollisionProfileName(PROFILE_NAME);

    mesh = CreateDefaultSubobject<UStaticMeshComponent>(SOBJ_MESH);
    mesh->SetupAttachment(RootComponent);

    static ConstructorHelpers::FObjectFinder<UStaticMesh> asset(SPHR_DIR);
    if (asset.Succeeded())
    {
        mesh->SetStaticMesh(SphereVisualAsset.Object);
        mesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
        mesh->SetWorldScale3D(FVector(0.3f));
        mesh->SetSimulatePhysics(true);
        mesh->WakeRigidBody();
    }

#undef SOBJ_ROOT
#undef SOBJ_MESH
#undef PROFILE_NAME
#undef SPHR_DIR
}

void AProjectile::BeginPlay()
{
    Super::BeginPlay();

    FRotator cameraRotation = GetCameraRotation();

    FVector up, forward, upAndForward;
    up = RotationToDirection(cameraRotation, EAxis::Z) * UpwardForce;
    forward = RotationToDirection(cameraRotation, EAxis::X) * ForwardForce;
    upAndForward = up + forward;

    mesh->AddImpulse(upAndForward);
}

void AProjectile::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    FVector l = GetActorLocation();
    if (l.Z < -50000.0f)
        Destroy();
}

(FYI - The overuse of temp variables and the #define stuff is for readability. The engine and API enjoy naming things so long they need punctuation, but this site wraps on 80 char columns.)

Visually, things are working as expected. However, when viewing properties of the items that are spawned, only the innermost “component” has it’s Z adjusting. The “Root Component” (Assuming that is the correct term), and the one in between have a static position. Nothing spawned ever gets deleted.

When I add force to the mesh I created, mesh->AddImpulse(upAndForward);, how do I make that force effect everything associated with that mesh?

Thanks in advance for any help!

Simply had to move the physics items to the Root Component instead of the second component created (the mesh).

Possible Duplicate