RevenantX / LiteEntitySystem

Pure C# HighLevel API for multiplayer games
Apache License 2.0
206 stars 25 forks source link

Can't get entity previously constructed during the same client tick #19

Closed Logerfo closed 1 year ago

Logerfo commented 1 year ago

ClientEntityManager#Deserialize(byte*, int) calls ConstructAndSync(true) only after constructing every pending entity, which is a problem when my entity constructor calls GetEntities<T> looking for a previously constructed entity during the same client tick. Would it be possible to sync every time after constructing each entity? I cannot postpone entity search because it's a dependency for Sync vars, which should be readonly! Am I using a bad practice here? Am I suppose to achieve the behavior I want in a different way?

RevenantX commented 1 year ago

@Logerfo it's better not to use actual Constructor for such things. Just move all logic that uses other entities and EntityManager to OnConstructed

RevenantX commented 1 year ago

@Logerfo also syncvars isnt readonly. ReadOnly is only SyncableFields, but you can pass anything to them after constructing

Logerfo commented 1 year ago

Using OnConstructed worked! You're right about syncvar/syncfield, but using SyncBool I have to wait for the other entity, so I had resize it. Thank you!