Client: Canary Server: 3874 (latest at time of writing.) OneSync: Yes (+set onesync on) Game Builds: 1604, 2060, 2189
Expected Outcome:
Setting a state bag on a new, owned entity on the client with the replication flag true as described in State bags, the state bag is replicated to the server.
Actual Outcome:
The state bag is not replicated to the server.
Example Code:
Client:
local object = CreateObject(`prop_alien_egg_01`, GetEntityCoords(PlayerPedId()), true, true)
Entity(object).state:set('foo', 'bar', true)
print('Set \'foo\' State Bag', Entity(object).state.foo)
-- Output of second parameter is "bar".
Server:
for _, entityId in pairs(GetAllObjects()) do
if GetEntityModel(entityId) == `prop_alien_egg_01` then
print('Alien Egg Found', entityId, Entity(entityId).state.foo)
-- Output of third parameter is nil.
end
end
That’s the issue - design limitation at this point since state is a sideband similar to events: the server won’t know of the entity yet until later on, as the state update gets sent too early oftentimes.
What is the point of state bags if it don’t get replicated to server? The main reason for using state bags is not wanting to use callbacks or events to sync data.
Player state bags are getting replicated. Just Entity’s are not getting replicated. Idk if that’s design or bug.
It does, though, and the topic here also provided a workaround: wait until the server knows of the entity before setting the state value.
What is the point of complaining ‘what is the point’ on a 5 month old topic instead of providing a constructive question with code/other actionable things?