Unreal Engine C++ Course | ENG
  • About course
  • Links
    • Git
    • Visual Studio
    • Unreal Engine
  • Unreal Editor Hotkeys
  • Visual Studio Hotkeys
  • Console commands
  • Problems and solutions
    • Unable to start program error
  • Lessons
    • Lecture 065
      • Additive animation upon landing
      • Blocking shooting while running
    • Lecture 079
      • Pickup is visible after the ammo has been taken
      • Ammo is not picked up if character spends ammo at the pickup respawn point
    • Lecture 089
      • NiagaraSystem does not attach to muzzle
    • Lecture 148
    • Lecture 155
  • UE5
  • Automation
    • Code formatting
  • Student projects
Powered by GitBook
On this page
  • Problem
  • What's happening
  • Solution

Was this helpful?

  1. Lessons
  2. Lecture 079

Pickup is visible after the ammo has been taken

Problem

  • Take pickup

  • Get up on the pickup respawn point

  • Spend all the ammo

  • Pickup respawns

  • Ammo is taken, but the pickup remains visible

What's happening

This happens due to the wrong execution order in ASTUBasePickup:

CollisionComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap);
if (GetRootComponent())
{
    GetRootComponent()->SetVisibility(true, true);
}
  • Pickup respawns

  • Collision is set to ECollisionResponse::ECR_Overlap

  • NotifyActorBeginOverlap is called

  • Pickup is taken and visibility is set to false

  • But after that, visibility is set to true (line 4)

Solution

Just change the order:

if (GetRootComponent())
{
     GetRootComponent()->SetVisibility(true, true);
}
CollisionComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap);
PreviousLecture 079NextAmmo is not picked up if character spends ammo at the pickup respawn point

Last updated 3 years ago

Was this helpful?

Commit in repository