[SOLVED] Question about auto state and replication

Discussions about Coding and Scripting
nogardilaref
Masterful
Posts: 577
Joined: Tue Jun 20, 2017 1:00 pm
Personal rank: ⚋⚊⚌☰⚞⌖⚟☰⚌⚊⚋

Re: [SOLVED] Question about auto state and replication

Post by nogardilaref »

Yeah, you're right, even the BeginPlay events are called before.

I just checked the Wiki now, to see if there's anything else you could use, and apparently, while PreBeginPlay, BeginPlay and PostBeginPlay are all called before SetInitialState, there's PostNetBeginPlay which is actually called afterwards, if you want to give it a try.
And it seems the only usable normal event which does so.
User avatar
PrinceOfFunky
Godlike
Posts: 1200
Joined: Mon Aug 31, 2015 10:31 pm

Re: [SOLVED] Question about auto state and replication

Post by PrinceOfFunky »

nogardilaref wrote:Yeah, you're right, even the BeginPlay events are called before.

I just checked the Wiki now, to see if there's anything else you could use, and apparently, while PreBeginPlay, BeginPlay and PostBeginPlay are all called before SetInitialState, there's PostNetBeginPlay which is actually called afterwards, if you want to give it a try.
And it seems the only usable normal event which does so.
You probably missed one or two EDITs from the previous post lol.
But yeah I should better use it then, since it's better than creatng a brand new state.

EDIT: Mhm, PostNetBeginPlay() is not called at all, probably cause of RemoteRole=ROLE_None.
"Your stuff is known to be buggy and unfinished/not properly tested"
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: [SOLVED] Question about auto state and replication

Post by sektor2111 »

Whatever has RemoteRole NONE and is coming later not mapped, probably is not even that much in account in player because it does not replicating changes.
Higor has done samples about dual operations server and client replication can even start controlled in a random moment, it doesn't need to be defaulted.
nogardilaref
Masterful
Posts: 577
Joined: Tue Jun 20, 2017 1:00 pm
Personal rank: ⚋⚊⚌☰⚞⌖⚟☰⚌⚊⚋

Re: [SOLVED] Question about auto state and replication

Post by nogardilaref »

Given that you're spawning the particles client-side only, the RemoteRole is actually meaningless, since the local role in the client is always ROLE_Authority in this case, given that it doesn't even have a copy of itself in the server.

Having that said, I personally never understood very well how PostNetBeginPlay works (if anyone could shed some light here it would be awesome).
There are conditions in which it is called, and others in which it simply isn't. Apparently it is supposed to be always called for runtime spawned actors after SetInitialState, and before SetInitialState and for actors with bScriptInitialized=false placed in the map itself, and in the case of replicated actors, after the first full replication has finished.

So in this case it should have been called without issues, but apparently there might be other gotchas we're not aware of.
Either way, I never really bothered to investigate it further since I also had problems with it, where it would work sometimes and other times it wouldn't, so whenever I needed something similar, I did it in a different way, and in a way it was sure to work, through the usage of Tick as an event handler.

Thus perhaps your initial state approach might actually be the way to go.
Post Reply