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.
User avatar
TheMIDIMan
Posts: 12
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
You do not have the required permissions to view the files attached to this post.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49183
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: 12
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: 49183
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: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

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

Return to “Closed Bugs [GZDoom]”