SC_Spawnables_MultipleSpawnsFromSingleTicket.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. def SC_Spawnables_MultipleSpawnsFromSingleTicket():
  7. import azlmbr.entity as entity
  8. import azlmbr.bus as bus
  9. import azlmbr.legacy.general as general
  10. from editor_python_test_tools.utils import TestHelper as helper
  11. def validate_entities_in_edit_mode(condition):
  12. search_filter = entity.SearchFilter()
  13. search_filter.names = ["SC_Spawner"]
  14. spawner_entity = entity.SearchBus(bus.Broadcast, 'SearchEntities', search_filter)[0]
  15. search_filter.names = ["PinkFlower"]
  16. flower_entity = entity.SearchBus(bus.Broadcast, 'SearchEntities', search_filter)
  17. assert spawner_entity is not None, f"Failed to find Spawner entity {condition}"
  18. assert len(flower_entity) == 0, f"Unexpectedly found PinkFlower entity {condition}"
  19. helper.init_idle()
  20. helper.open_level("Prefab", "SC_Spawnables_MultipleSpawnsFromSingleTicket")
  21. # Search for expected entities in edit mode
  22. validate_entities_in_edit_mode("before entering Game Mode")
  23. # Enter Game Mode and allow SC logic to run. Graph will execute the "quit" command and exit Game Mode if all
  24. # expected entities are found at runtime
  25. general.enter_game_mode()
  26. # Wait for Game Mode exit via SC graph and verify despawn of all SpawnablesTestEntity instances
  27. game_mode_exited = helper.wait_for_condition(lambda: not general.is_in_game_mode(), 5.0)
  28. assert game_mode_exited, "SC Graph failed to exit Game Mode"
  29. validate_entities_in_edit_mode("after exiting Game Mode")
  30. if __name__ == "__main__":
  31. from editor_python_test_tools.utils import Report
  32. Report.start_test(SC_Spawnables_MultipleSpawnsFromSingleTicket)