Entity spawn and world chunks

So, im creating a game, with procedural world, which separated by chunks.
When game shoots event on spawning bunch of entities, it looks near to player chunks, and then spawns them in, but if player runs away, world gonna be unloaded, and then entity should fall, isn’t it?
My question is:
How im gonna handle entities, note that they cannot be despawned(they go back to spawns when day starts), and world is procedural?

1 Like

My advice would be to anchor (and/or hide) them, so that when the chunk is reloaded again, the entity would be in the exact same place. When unloading a chunk, you could use workspace:GetPartBoundsInBox() to detect any entities inside a chunk.

1 Like

Anchor their “HumanoidRootPart” by putting a script in them when their chunk is unloaded.

1 Like

Hm, so when chunk is unloaded i anchor them?
I can try to write some pseudo-code for algorithm

if chunk_is_unloaded() and time_is_night()
   Entity:Anchor()
elif chunk_is_unloaded() and time_is_day()
   Entity:Destroy()
endif
1 Like

Entity.HumanoidRootPart.Anchored = true :slight_smile:

1 Like

It was a pseudo-code, so, anyway, ig it’s the only right way to do this task.

2 Likes