PreBeginPlay v.s. PostBeginPlay - Noob questions

Discussions about Coding and Scripting
Post Reply
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

PreBeginPlay v.s. PostBeginPlay - Noob questions

Post by MrLoathsome »

Scenario. I have been working on a mutator, that has had a considerable amount of processing going on in
the PostBeginPlay function. All has been well.

Decided to add 2 statements to the initialization for the mutator that needed to be in PreBeginPlay.

So I just stuck them into the existing PostBeginPlay and renamed it to PreBeginPlay.

All the stuff I had in PostBeginPlay before seems to work fine in either function.

My noobish questions:

Would there be any performance advantage if I moved the bulk of the code that works fine in either
function back into PostBeginPlay?
Does this cause some problem I haven't discovered yet? Or is it ok just to leave it all in PreBeginPlay?
blarg
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: PreBeginPlay v.s. PostBeginPlay - Noob questions

Post by Feralidragon »

The only difference between Post and Pre, besides the order they are called, is that in Pre the zone info was not set yet for the actor, and the encroachment check was not made yet either.
You can see this info here: http://wiki.beyondunreal.com/Legacy:Cha ... s#...in_UT

There's no difference in performance, it's mostly if it's important or not process something before or after the events between Pre and Post.
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: PreBeginPlay v.s. PostBeginPlay - Noob questions

Post by Higor »

If you destroy an actor in PreBeginPlay(), BeginPlay() isn't called.
If you destroy an actor in or before BeginPlay(), PostBeginPlay() isn't called.

PreBeginPlay() has a general definition in all actors which allows them to be 'mutated', an actor with an overriden PreBeginPlay() without a Super.PreBeginPlay() call inside will not be affected by mutators, which isn't necessarily a good thing.
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: PreBeginPlay v.s. PostBeginPlay - Noob questions

Post by MrLoathsome »

Thanks to both of you for the replies. Exactly the info I needed.

Some of the processing I got in there does indeed reference .Region.Zone info.

I am going to separate things, and have a short PreBeginPlay, and larger PostBeginPlay.
Both will have a call to Super in them.

That will be the best way I think, and make the code look a bit nicer.

Edit---

While I have your attention.... One of the things I want to do is have the mutator
unload itself right away, if the gametype is Assault.
Here are the 1st two lines in my current PreBeginPlay() function:

Code: Select all

	Super.PreBeginPlay();
	If (Level.Game.IsA('Assault')) { Self.Destroy(); return; }
That seems to work perfect, but figured I might as well check with you guys to
see if there is a better way, or if that causes some problems I haven't yet encountered
in testing.
blarg
Post Reply