reeseschultz / ReeseUnityDemos

Unity packages and demos—emphasizing ECS, jobs and the Burst compiler—by Reese and others.
https://reese.codes
MIT License
516 stars 45 forks source link

Add nav respawn demo system #7

Closed reeseschultz closed 4 years ago

reeseschultz commented 4 years ago

If an agent falls by trying to jump too close to an edge (which is a feature, not a bug), then having a respawn demo system would be useful not only as an example, but also for the NavMovingJumpDemo and NavPointAndClickDemo, seeing as agents can fall and never get replaced. Like the NavFallSystem and NavSpawnSystem, this would not be part of the core nav code, since it's up to users to handle spawning and falling (these are specific to the game or simulation one is trying to make).

I'm not entirely sure on the details, but my first impression on creating a respawn system would be that we essentially want to aim for some number of agents at all times. That number should be configurable on a scene-by-scene basis. Obviously when the number is not met via a count query, we run Enqueue on an injected NavSpawnSystem. Only corner case that comes to mind rn is that the prefab for agents may count as a bona fide agent, so I'll have to account for that.

Edit: See below comment.

reeseschultz commented 4 years ago

Better idea.

Add a NavRespawnable component to Assets/Scripts/Demo/Nav. It won't go in NavAgentStatus because that would mislead users into thinking it's used in the core nav code, but actually it would only be used in the nav demo code. This is a helper tag to nudge users to handle "respawnability" in a queryable and configurable way. I could see some users modifying NavRespawnable to even include different data, maybe a counter of the times an agent has respawned, which would affect a respawn wait duration.

Anyway, I could rename the NavFallSystem to NavFallAndRespawnSystem, so its logic would change such that those who've fallen too long will die, except for those with NavRespawnable—they will "come back to life."

reeseschultz commented 4 years ago

I changed my mind again and thought yesterday I'd just reset any agent back to the origin from the NavFallSystem, logging what happened—no extra components needed.

Then I realized it would be convenient to have a status reset feature for agents, rather than destroying them and literally spawning new ones. I discovered doing that is plagued with the same issue mentioned in #8: I can't change parents more than once without the built-in ParentSystem reporting a full hashmap. I'll have to report this as a bug to the Unity folks.

reeseschultz commented 4 years ago

This can be revisited since I haven't encountered the parenting changing issue for a while.

reeseschultz commented 4 years ago

Closing since this may be scene specific.