Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CsvSpawner - fix spawning when the terrain is included #102

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

w-czerski
Copy link
Contributor

@w-czerski w-czerski commented Jan 14, 2025

About:

This PR introduces improvement to the CsvSpawner.
❌ Removed frame skipping and counting
✅ Rely on built in Bus Notifies in AzFramework::Terrain

Entities are spawned based on Terrain availability.
If not available- call SpawnEntities() in first available frame (like it was done before).

Component Type Improvement Description
Game Component If Terrain exists - spawn will be called upon OnTerrainCreateEnd(),
otherwise queue spawn on activation.
Editor Component If Terrain exists - spawn will be called upon OnTerrainDataChanged(), otherwise queue spawn on activation.
Editor has dedicated masks to filter important updates, that indicate is terrain created properly - so call happens only once.

Why use different events?

  • OnTerrainCreateEnd() - notifies when Terrain is Activated, launched at finish.
  • OnTerrainDataChanged - notifies every time when Terrain Data has changed inside Tick.

Terrain is being initiated not only in Activate(), but OnTick(). This generates some problems while being in Editor.
Since physics don't work the same way as in game mode, editor needs another approach. It is possible to filter every Terrain updates with masks (flags), and SpawnEntities() when Terrain is ready.

Features (in Editor)

Terrain is not available in the level Terrain is available in the level
Screenshot from 2025-01-16 18-10-37 Screenshot from 2025-01-16 18-11-00
  • SpawnOnEditorConfig: Spawns entities when the level is loaded (on activation).
  • SpawnOnTerrainUpdate: Spawns entities when the terrain is updated, such as when terrain is moved, its transform is changed, terrain system settings are altered, or the terrain is regenerated. It also adjusts spawned entities to reflect these changes.
  • TerrainFlagsToIgnore: Filter masks that prevent unwanted updates of terrain in the editor before spawning. You can keep SpawnOnTerrainUpdate enabled and specify which updates should trigger entity spawning.

Example

  1. On level opened, entities will be spawned. Changes made to terrain settings and color data won't trigger spawn entities.
SpawnOnEditorConfig = ON
SpawnOnTerrainUpdate = ON
TerrainFlagsToIgnore = {Settings + Color Data}
  1. On level opened, entities won't be spawned. Changes made to any terrain settings, data, transform will trigger update spawn entities.
 SpawnOnEditorConfig = OFF
 SpawnOnTerrainUpdate = ON
 TerrainFlagsToIgnore = {None}
  1. On level opened, entities will be spawned. Any changes made to terrain won't spawn entities. Automatically - Terrain Flags are set to ignore all masks.
 SpawnOnEditorConfig = ON
 SpawnOnTerrainUpdate = OFF
 TerrainFlagsToIgnore = {All}

@w-czerski w-czerski changed the title [Draft] CsvSpawner - fix on edit [Draft] CsvSpawner - fix spawning when the terrain is included Jan 14, 2025
Signed-off-by: Wojciech Czerski <[email protected]>
Signed-off-by: Wojciech Czerski <[email protected]>
@w-czerski w-czerski self-assigned this Jan 14, 2025
@w-czerski w-czerski force-pushed the wc/terrain_notify_update branch from 496fa39 to 3871fac Compare January 14, 2025 15:58
Signed-off-by: Wojciech Czerski <[email protected]>
Signed-off-by: Wojciech Czerski <[email protected]>
Signed-off-by: Wojciech Czerski <[email protected]>
…ibility of the button based on is terrain available

Signed-off-by: Wojciech Czerski <[email protected]>
… is active for both (with terrain and without)

Signed-off-by: Wojciech Czerski <[email protected]>
Signed-off-by: Wojciech Czerski <[email protected]>
Signed-off-by: Wojciech Czerski <[email protected]>
Signed-off-by: Wojciech Czerski <[email protected]>
@w-czerski
Copy link
Contributor Author

w-czerski commented Jan 16, 2025

Also please note, that solution in editor Reflcet of Enums TerrainChangedDataMask is a dirty hack. I couldnt manage o3de to work with AZStd::vector<TerrainChangedDataMask> - it always resulted in crash. If you have any solution for this, let me know.

@w-czerski w-czerski changed the title [Draft] CsvSpawner - fix spawning when the terrain is included CsvSpawner - fix spawning when the terrain is included Jan 16, 2025
Copy link
Contributor

@patrykantosz patrykantosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor comments.

Signed-off-by: Wojciech Czerski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants