PostBeginPlay() doesn't get called in certain situations

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
TheMIDIMan
Posts: 6
Joined: Wed Jun 01, 2022 3:46 am
Location: ZScript purgatory

PostBeginPlay() doesn't get called in certain situations

Post by TheMIDIMan »

When starting a new game from the menu the custom PlayerPawn calls BeginPlay() and PostBeginPlay() correctly. (see console)
But when starting another lever (in the example level, by pulling the switch) the custom PlayerPawn calls BeginPlay() twice and doesn't even call PostBeginPlay() once! (see console)

Additional info:
- the console command "map *" works correctly (BeginPlay() and PostBeginPlay() called), but "changemap *" doesn't (BeginPlay() called twice)
- problem only exists in PlayerPawn (as far as I'm aware)

Provided in this .zip-file:
- ZScript PlayerPawn definition
- MapInfo definition for test level
- test level for proof


I'm using GZDoom 4.10.0 and ZScript 4.10.0
Attachments
Example.zip
Minimal example (ZScript, MapInfo, and a level)
(1.35 KiB) Downloaded 7 times
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: PostBeginPlay() doesn't get called in certain situations

Post by Graf Zahl »

This is because the freshly spawned PlayerPawn is not kept around. Your original player from the previous level will take over and the new ones be destroyed before PostBeginPlay is ever reached
User avatar
TheMIDIMan
Posts: 6
Joined: Wed Jun 01, 2022 3:46 am
Location: ZScript purgatory

Re: PostBeginPlay() doesn't get called in certain situations

Post by TheMIDIMan »

So the newly spawned PlayerPawn and the player carried over from the previous level both call BeginPlay but neither of them call PostBeginPlay?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: PostBeginPlay() doesn't get called in certain situations

Post by Graf Zahl »

No, the original player does not call BeginPlay. The engine spawns two new players on the new map and ultimately destroys both of them again.
You cannot rely on these two functions for players.
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: PostBeginPlay() doesn't get called in certain situations

Post by Nash »

Use the PlayerSpawned and/or PlayerEntered to reliably run code on player actors.

https://zdoom.org/wiki/Events_and_handlers
Post Reply

Return to “Closed Bugs [GZDoom]”