Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

instantiateEntity error

Discussion in 'Project Tiny' started by WellC, Dec 31, 2018.

  1. WellC

    WellC

    Joined:
    Mar 2, 2015
    Posts:
    48
    I want to instantiate a sprite and set its position, rotation, scale, but there is no way to use GetcomponentData.
    This my code:
    Code (CSharp):
    1.  
    2. namespace game {
    3.     export class SpawnerFilter extends ut.EntityFilter {
    4.         spanwer: game.Spawner;
    5.         entity: ut.Entity;
    6.     }
    7.     export class SpawnerSystem extends ut.ComponentSystem {
    8.         spawnerFilter: SpawnerFilter = new SpawnerFilter();
    9.         OnUpdate(): void {
    10.  
    11.             this.spawnerFilter.ForEach(this.world, (entity) => {
    12.                 var spawner = this.spawnerFilter.spanwer;
    13.                 var secondsBetweenSpawns = game.GameServices.lerp(spawner.secondsBetweenSpawnsMinMax.y,
    14.                     spawner.secondsBetweenSpawnsMinMax.x,
    15.                     game.GameServices.getDifficultyPercent(this.world));
    16.  
    17.                 spawner.nextSpawnTime = game.Time.time() + secondsBetweenSpawns;
    18.  
    19.  
    20.                 var tmp_SpawnAngle = game.GameServices.getRandomRange(-spawner.spawnAngleMax, spawner.spawnAngleMax);
    21.                 var tmp_SpawnSize = game.GameServices.getRandomRange(spawner.spawnSizeMinMax.x, spawner.spawnSizeMinMax.y);
    22.                 var tmp_SpawnPosition = new Vector3(game.GameServices.getRandomRange(-spawner.screenHalfSizeWorldUnits.x, spawner.screenHalfSizeWorldUnits.x), spawner.screenHalfSizeWorldUnits.y + tmp_SpawnSize, 0);
    23.  
    24.                 let tmp_Entity = this.world.instantiateEntity(spawner.fallingBlockPrefab);
    25.                 this.world.getComponentData(tmp_Entity, ut.Core2D.TransformLocalPosition).position = tmp_SpawnPosition;
    26.                 this.world.getComponentData(tmp_Entity, ut.Core2D.TransformLocalScale).scale = new Vector3(tmp_SpawnSize, tmp_SpawnSize, tmp_SpawnSize);
    27.                 this.world.getComponentData(tmp_Entity, ut.Core2D.TransformLocalRotation).rotation.z = tmp_SpawnAngle;
    28.             });
    29.         }
    30.     }
    31. }
    32.  
    The error:
    Code (CSharp):
    1.  
    2. Deferred entity didn't have component from getComponentDataRawUnsafe
    3. (anonymous) @ runtime.js:980
    4. _emscripten_asm_const_ii @ runtime.js:1000
    5. __ZN2ut12assertFailedEPKcS1_S1_j @ runtime.js:224
    6. __ZN2ut4arch13EntityManager25getComponentDataRawUnsafeENS_6EntityEj @ runtime.js:683
    7. __ZN2ut4arch13EntityManager19getComponentDataRawENS_6EntityEjPvj @ runtime.js:2174
    8. _ut_World_GetComponentDataRaw @ runtime.js:6020
    9. (anonymous) @ runtime.js:127626
    10. (anonymous) @ tsc-emit.js:124
    11. (anonymous) @ main.js:71
    12. (anonymous) @ runtime.js:127759
    13. game.SpawnerFilter.ForEach @ main.js:69
    14. SpawnerSystem.OnUpdate @ tsc-emit.js:116
    15. (anonymous) @ bindings.js:1477
    16. (anonymous) @ runtime.js:978
    17. _emscripten_asm_const_iiii @ runtime.js:997
    18. _ut_SystemFn_call @ runtime.js:6613
    19. __ZNSt3__228__invoke_void_return_wrapperIvE6__callIJRNS_6__bindIRFvjPN2ut9SchedulerEPNS4_12ManagerWorldEEJRjRKNS_12placeholders4__phILi1EEERKNSD_ILi2EEEEEES6_S8_EEEvDpOT_ @ runtime.js:4435
    20. __ZNSt3__210__function6__funcINS_6__bindIRFvjPN2ut9SchedulerEPNS3_12ManagerWorldEEJRjRKNS_12placeholders4__phILi1EEERKNSC_ILi2EEEEEENS_9allocatorISJ_EEFvS5_S7_EEclEOS5_OS7_ @ runtime.js:4434
    21. __ZNKSt3__28functionIFvPN2ut9SchedulerEPNS1_12ManagerWorldEEEclES3_S5_ @ runtime.js:4832
    22. __ZN2ut12SimpleSystem6updateERNS_9SchedulerERNS_12ManagerWorldE @ runtime.js:5089
    23. __ZN2ut9Scheduler3runENSt3__26chrono10time_pointINS2_12steady_clockENS2_8durationIxNS1_5ratioILx1ELx1000000000EEEEEEE @ runtime.js:1022
    24. __ZN2ut9Scheduler3runEv @ runtime.js:2306
    25. __ZN2ut4HTML11HTMLPrivate17mainLoopIterationEv @ runtime.js:2303
    26. __ZN2ut4HTML11HTMLService17mainLoopForwarderEv @ runtime.js:6127
    27. dynCall_v @ runtime.js:7115
    28. mainLoop @ runtime.js:1688
    29. setTimeout (async)
    30. _js_set_main_loop_v @ runtime.js:1686
    31. __ZN2ut4HTML11HTMLService3runEPNS_12ManagerWorldE @ runtime.js:5959
    32. _ut_HTML_HTMLService_Run @ runtime.js:6541
    33. (anonymous) @ runtime.js:142711
    34. ut.main @ main.js:124
    35. run @ runtime.js:142752
    36. (anonymous) @ runtime.js:143141
    37. (anonymous) @ runtime.js:142756
    38. (anonymous) @ (index):14
    39. load (async)
    40. (anonymous) @ (index):14
    41. runtime.js:126115 Assertion failed: entity.index >= 0, at: C:/Users/Abdul/Documents/tiny/Runtime/modules/core/src/arch/EntityManager.cpp,357,
    42. runtime.js:126116 Assertion failed: entity.index >= 0, at: C:/Users/Abdul/Documents/tiny/Runtime/modules/core/src/arch/EntityManager.cpp,357,
    43. abort @ runtime.js:126116
    44. ___assert_fail @ runtime.js:1047
    45. __ZN2ut12assertFailedEPKcS1_S1_j @ runtime.js:224
    46. __ZN2ut4arch13EntityManager25getComponentDataRawUnsafeENS_6EntityEj @ runtime.js:683
    47. __ZN2ut4arch13EntityManager19getComponentDataRawENS_6EntityEjPvj @ runtime.js:2174
    48. _ut_World_GetComponentDataRaw @ runtime.js:6020
    49. (anonymous) @ runtime.js:127626
    50. (anonymous) @ tsc-emit.js:124
    51. (anonymous) @ main.js:71
    52. (anonymous) @ runtime.js:127759
    53. game.SpawnerFilter.ForEach @ main.js:69
    54. SpawnerSystem.OnUpdate @ tsc-emit.js:116
    55. (anonymous) @ bindings.js:1477
    56. (anonymous) @ runtime.js:978
    57. _emscripten_asm_const_iiii @ runtime.js:997
    58. _ut_SystemFn_call @ runtime.js:6613
    59. __ZNSt3__228__invoke_void_return_wrapperIvE6__callIJRNS_6__bindIRFvjPN2ut9SchedulerEPNS4_12ManagerWorldEEJRjRKNS_12placeholders4__phILi1EEERKNSD_ILi2EEEEEES6_S8_EEEvDpOT_ @ runtime.js:4435
    60. __ZNSt3__210__function6__funcINS_6__bindIRFvjPN2ut9SchedulerEPNS3_12ManagerWorldEEJRjRKNS_12placeholders4__phILi1EEERKNSC_ILi2EEEEEENS_9allocatorISJ_EEFvS5_S7_EEclEOS5_OS7_ @ runtime.js:4434
    61. __ZNKSt3__28functionIFvPN2ut9SchedulerEPNS1_12ManagerWorldEEEclES3_S5_ @ runtime.js:4832
    62. __ZN2ut12SimpleSystem6updateERNS_9SchedulerERNS_12ManagerWorldE @ runtime.js:5089
    63. __ZN2ut9Scheduler3runENSt3__26chrono10time_pointINS2_12steady_clockENS2_8durationIxNS1_5ratioILx1ELx1000000000EEEEEEE @ runtime.js:1022
    64. __ZN2ut9Scheduler3runEv @ runtime.js:2306
    65. __ZN2ut4HTML11HTMLPrivate17mainLoopIterationEv @ runtime.js:2303
    66. __ZN2ut4HTML11HTMLService17mainLoopForwarderEv @ runtime.js:6127
    67. dynCall_v @ runtime.js:7115
    68. mainLoop @ runtime.js:1688
    69. setTimeout (async)
    70. _js_set_main_loop_v @ runtime.js:1686
    71. __ZN2ut4HTML11HTMLService3runEPNS_12ManagerWorldE @ runtime.js:5959
    72. _ut_HTML_HTMLService_Run @ runtime.js:6541
    73. (anonymous) @ runtime.js:142711
    74. ut.main @ main.js:124
    75. run @ runtime.js:142752
    76. (anonymous) @ runtime.js:143141
    77. (anonymous) @ runtime.js:142756
    78. (anonymous) @ (index):14
    79. load (async)
    80. (anonymous) @ (index):14
    81. runtime.js:126123 Uncaught abort("Assertion failed: entity.index >= 0, at: C:/Users/Abdul/Documents/tiny/Runtime/modules/core/src/arch/EntityManager.cpp,357,"). Build with -s ASSERTIONS=1 for more info.
    82. abort @ runtime.js:126123
    83. ___assert_fail @ runtime.js:1047
    84. __ZN2ut12assertFailedEPKcS1_S1_j @ runtime.js:224
    85. __ZN2ut4arch13EntityManager25getComponentDataRawUnsafeENS_6EntityEj @ runtime.js:683
    86. __ZN2ut4arch13EntityManager19getComponentDataRawENS_6EntityEjPvj @ runtime.js:2174
    87. _ut_World_GetComponentDataRaw @ runtime.js:6020
    88. (anonymous) @ runtime.js:127626
    89. (anonymous) @ tsc-emit.js:124
    90. (anonymous) @ main.js:71
    91. (anonymous) @ runtime.js:127759
    92. game.SpawnerFilter.ForEach @ main.js:69
    93. SpawnerSystem.OnUpdate @ tsc-emit.js:116
    94. (anonymous) @ bindings.js:1477
    95. (anonymous) @ runtime.js:978
    96. _emscripten_asm_const_iiii @ runtime.js:997
    97. _ut_SystemFn_call @ runtime.js:6613
    98. __ZNSt3__228__invoke_void_return_wrapperIvE6__callIJRNS_6__bindIRFvjPN2ut9SchedulerEPNS4_12ManagerWorldEEJRjRKNS_12placeholders4__phILi1EEERKNSD_ILi2EEEEEES6_S8_EEEvDpOT_ @ runtime.js:4435
    99. __ZNSt3__210__function6__funcINS_6__bindIRFvjPN2ut9SchedulerEPNS3_12ManagerWorldEEJRjRKNS_12placeholders4__phILi1EEERKNSC_ILi2EEEEEENS_9allocatorISJ_EEFvS5_S7_EEclEOS5_OS7_ @ runtime.js:4434
    100. __ZNKSt3__28functionIFvPN2ut9SchedulerEPNS1_12ManagerWorldEEEclES3_S5_ @ runtime.js:4832
    101. __ZN2ut12SimpleSystem6updateERNS_9SchedulerERNS_12ManagerWorldE @ runtime.js:5089
    102. __ZN2ut9Scheduler3runENSt3__26chrono10time_pointINS2_12steady_clockENS2_8durationIxNS1_5ratioILx1ELx1000000000EEEEEEE @ runtime.js:1022
    103. __ZN2ut9Scheduler3runEv @ runtime.js:2306
    104. __ZN2ut4HTML11HTMLPrivate17mainLoopIterationEv @ runtime.js:2303
    105. __ZN2ut4HTML11HTMLService17mainLoopForwarderEv @ runtime.js:6127
    106. dynCall_v @ runtime.js:7115
    107. mainLoop @ runtime.js:1688
    108. setTimeout (async)
    109. _js_set_main_loop_v @ runtime.js:1686
    110. __ZN2ut4HTML11HTMLService3runEPNS_12ManagerWorldE @ runtime.js:5959
    111. _ut_HTML_HTMLService_Run @ runtime.js:6541
    112. (anonymous) @ runtime.js:142711
    113. ut.main @ main.js:124
    114. run @ runtime.js:142752
    115. (anonymous) @ runtime.js:143141
    116. (anonymous) @ runtime.js:142756
    117. (anonymous) @ (index):14
    118. load (async)
    119. (anonymous) @ (index):14
    120.  
    121.  
     
  2. nik_ai

    nik_ai

    Joined:
    Jun 14, 2017
    Posts:
    9
    @WellC

    You have to use this.world.setComponentData

    Code (JavaScript):
    1. let transformComponentToBeEdit = this.world.getComponentData(entityThatContainsTransform, ut.Core2D.TransformLocalPosition);                  
    2.                     transformComponentToBeEdit.position = new Vector3(0, 0, 0);
    3.                     this.world.setComponentData(entityThatContainsTransform, transformComponentToBeEdit);
    4.                    
     
  3. WellC

    WellC

    Joined:
    Mar 2, 2015
    Posts:
    48
    I tried. But error always... Error at

    this.world.getComponentData(tmp_Entity, ut.Core2D.TransformLocalPosition);
    Error: Deferred entity didn't have component from getComponentDataRawUnsafe
     
  4. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    200
    Most likely your "fallingBlockPrefab" doesn't have a TransformLocalPosition component on it!

    Test like this :

    Code (JavaScript):
    1.  
    2. let tmp_Entity : ut.Entity = this.world.instantiateEntity(spawner.fallingBlockPrefab);
    3. if (this.world.exists(tmp_Entity)) {
    4.    let position : ut.Core2D.TransformLocalPosition = this.world.getComponentData(tmp_Entity, ut.Core2D.TransformLocalPosition);
    5.     if(position == undefined)
    6.    {
    7.       console.log("No TransformLocalPosition");
    8.    }
    9. }
    10.  

    Or you can add one on the fly

    Code (JavaScript):
    1. this.world.setOrAddComponentData(tmp_Entity, position);
     
    nik_ai likes this.
  5. WellC

    WellC

    Joined:
    Mar 2, 2015
    Posts:
    48
    Thanks for you reply.
    I tried your thoughts.
    There are Transform local position component.
    But the error is in getcomponentdata...I dont know why.
    this.world.getComponentData(tmp_Entity, ut.Core2D.TransformLocalPosition);