Description

FSuggestProjectileVelocityParameters was introduced in 5.4 and has a FCollisionResponseParams member that's initialized as a mutable reference to FCollisionResponseParams::DefaultResponseParam.

struct FSuggestProjectileVelocityParameters
{
  ...
  public:
  FCollisionResponseParams& ResponseParam = FCollisionResponseParams::DefaultResponseParam; 
}

This is a problem because game code that declares a FSuggestProjectileVelocityParameters can modify FSuggestProjectileVelocityParameters. This makes it very easy for game code to unintentionally modify the global static DefaultResponseParam. See repro steps.

Steps to Reproduce

Run the following code on BeginPlay:

 

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

    UE_LOG(LogTemp, Warning, TEXT("Default collision response to WorldStatic before: %d"), int32(FCollisionResponseParams::DefaultResponseParam.CollisionResponse.GetResponse(ECC_WorldStatic)));

    const FVector StartLoc;
    const FVector EndLoc;
    UGameplayStatics::FSuggestProjectileVelocityParameters VelParams(GetWorld(), StartLoc, EndLoc, 1000.0f);
    VelParams.ResponseParam.CollisionResponse.SetResponse(ECC_WorldStatic, ECollisionResponse::ECR_Ignore);

    UE_LOG(LogTemp, Warning, TEXT("Default collision response to WorldStatic after: %d"), int32(FCollisionResponseParams::DefaultResponseParam.CollisionResponse.GetResponse(ECC_WorldStatic)));
}

Observe: the output of DefaultResponseParam.CollisionResponse.GetResponse() changes before and after the unrelated user code: 2 -> 0.

Expected: No change to DefaultResponseParam.CollisionResponse.GetResponse(): 2 -> 2.

 

 

 

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-224510 in the post.

1
Login to Vote

Unresolved
ComponentUE - Gameplay
Affects Versions5.4
Target Fix5.5
CreatedSep 17, 2024
ResolvedSep 17, 2024
UpdatedSep 27, 2024
View Jira Issue