Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

CS2: Randomly missing WeaponInstance.Entity on grenades #580

Open
@dankotov

Description

Describe the bug
Occasionally (about 10% from my testitng) grenades will have WeaponInstance.Entity as nil when retrieved inside event handler functions for events like WeaponFire or GrenadeProjectileThrown.

In WeaponFire events, this only happens to grenade weapons.

To Reproduce
Demos from any of the following, but not limited to matches:
https://www.hltv.org/matches/2378899/vitality-vs-faze-iem-katowice-2025
https://www.hltv.org/matches/2378897/eternal-fire-vs-virtuspro-iem-katowice-2025
https://www.hltv.org/matches/2378898/falcons-vs-g2-iem-katowice-2025

Code:

func main() {
 // ...
 p.RegisterEventHandler(func(e events.GrenadeProjectileThrow) {
 if e.Projectile.WeaponInstance.Entity == nil {
 fmt.Println("Missing Entity")
 }
 })
 // ...
}

Expected behavior
Every nade should have a corresponding WeaponInstance.Entity.

Library version
v4.3.3

Additional context
I have also observed, that for all of the nades in these demos, where WeaponInstance.Entity is missing, WeaponInstance.Owner is also missing.

I have also tested with the code below to confirm that the cause of this issue is not that those entities are destroyed when a grenade is thrown.

func main() {
 // ...
 lastNonNilWeaponEntities := make(map[ulid.ULID]st.Entity)
 
 p.RegisterEventHandler(func(e events.FrameDone) {
 for _, player := range p.GameState().Participants().Playing() {
 for _, weapon := range player.Weapons() {
 ent := weapon.Entity
 if ent == nil {
 continue
 }
 lastNonNilWeaponEntities[weapon.UniqueID2()] = weapon.Entity 
 }
 }
 })
 
 p.RegisterEventHandler(func(e events.GrenadeProjectileThrow) {
 projectileWeaponInstanceId := e.Projectile.WeaponInstance.UniqueID2()
 projectileWeaponInstanceEntity := lastNonNilWeaponEntities[projectileWeaponInstanceId]
 if projectileWeaponInstanceEntity == nil {
 fmt.Println("Missing Entity")
 return
 }
 })
 // ...
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /