InstantiatePrefab_ContainingASingleEntity.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 InstantiatePrefab_ContainingASingleEntity():
  7. from azlmbr.math import Vector3
  8. import azlmbr.legacy.general as general
  9. EXISTING_TEST_PREFAB_FILE_NAME = "Gem/PythonTests/Prefab/data/Test.prefab"
  10. INSTANTIATED_TEST_PREFAB_POSITION = Vector3(10.00, 20.0, 30.0)
  11. EXPECTED_TEST_PREFAB_CHILDREN_COUNT = 1
  12. from editor_python_test_tools.editor_entity_utils import EditorEntity
  13. from editor_python_test_tools.prefab_utils import Prefab
  14. from editor_python_test_tools.wait_utils import PrefabWaiter
  15. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  16. prefab_test_utils.open_base_tests_level()
  17. # Instantiates a new car prefab instance
  18. test_prefab = Prefab.get_prefab(EXISTING_TEST_PREFAB_FILE_NAME)
  19. test_instance = test_prefab.instantiate(
  20. prefab_position=INSTANTIATED_TEST_PREFAB_POSITION)
  21. # Get parent entity and container id for verifying successful Undo/Redo operations
  22. instance_parent_id = EditorEntity(test_instance.container_entity.get_parent_id())
  23. instance = test_instance.container_entity
  24. prefab_test_utils.check_entity_children_count(
  25. test_instance.container_entity.id,
  26. EXPECTED_TEST_PREFAB_CHILDREN_COUNT)
  27. # Undo the instantiation
  28. general.undo()
  29. PrefabWaiter.wait_for_propagation()
  30. child_ids = instance_parent_id.get_children_ids()
  31. assert instance.id not in child_ids, "Undo Failed: Instance was still found after undo."
  32. # Redo the instantiation
  33. general.redo()
  34. PrefabWaiter.wait_for_propagation()
  35. child_ids = instance_parent_id.get_children_ids()
  36. instance_children = instance.get_children()
  37. assert instance.id in child_ids, "Redo Failed: Instance was not found after redo"
  38. assert len(instance_children) == EXPECTED_TEST_PREFAB_CHILDREN_COUNT, \
  39. "Redo Failed: Did not find expected child entities in the prefab instance"
  40. if __name__ == "__main__":
  41. from editor_python_test_tools.utils import Report
  42. Report.start_test(InstantiatePrefab_ContainingASingleEntity)