When is the Actor Role safe to use

Hello,

I’m trying to find a good place to test the role of an actor in C++ as early as possible on a client. Basically I want to know if it is Role_SimulatedProxy or Role_AutonomousProxy. It appears that after PostInitializeComponents or BeginPlay, the role is still undefined. Only after the first tick i can get the correct value. Is there any other function before tick I could use?

Edit: It appears that the Role might not be reliable on the first tick neither. Should we have ReplicatingUsing on Role member variable in Actor class so we can have a callback the first time the Role is set?

Thanks in advance.

On the client, you should be able to safely use this after the first PostNetReceive call.

Hi,

We think this post contains useful information which we would like to share with our public UE4 community. With your approval, we would like to make a copy of this post on the public AnswerHub which includes the discussion but strips out your username and company name. Please let us know if you are okay with this.

Thanks John. Should BeginPlay and first tick only be called after that then? I might be mistaken but in UE3 i think we could use the Role of an actor on a client as soon as PostBeginPlay was called in script. Otherwise, all replicated actors which require to know their role will need to override that function and cache some kind of flag to know if their role is known. It just feels like it is some necessary overhead.

I think the problem is that PostBeginPlay is called inside the SpawnActor function, and the role hasn’t had a chance to even be replicated yet.

Absolutely fine.

Thank you!