I have implemented a sample ObjectPool in unreal engine, the core data like this structure: TMap<TSubClassOf, TTuple<Actor*, Actor*>> PooledActors.
The key is the object type, the value is a tuple which stored inactive and active actor’s pointer.
At runtime, I pulled actor from this pool and pushed to pool when I don’t need it. The Actor should implement OnPull/OnPush function to something like “SetHiddenInGame()”. Yeah, it is sample objectPool.
My question is what will happend if write to a pool when I am now reading it? This is very likely to happen for object pools. Should I need lock or something like that?
And I have done some google that somebody say: “if all logic happend on the same thread, you should not wrroy about it”.
- Is it correct?
- How to know if there will be multithreading?
- If the game thread for unreal engine is alway on single thread?
- If it is only on single thread, how is “FScopeLock” used in unreal engine’s source code?
- Can it solve all the problems by copying of the array for reading it?
Thanks for any reply!