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

BUG - RectTransform is undefined

Discussion in 'Project Tiny' started by DiegoDiKronos, May 31, 2019.

  1. DiegoDiKronos

    DiegoDiKronos

    Joined:
    Apr 26, 2019
    Posts:
    5
    I'm trying to do a little animation of vibrating in a square of a letter soup when the player fails, i made this code:
    Code (JavaScript):
    1. OnUpdate(): void {
    2.             let cont = 0;
    3.             this.world.forEach([ut.Entity, game.AnimationData, game.G3_Data], (entity, AnimData) => {
    4.                 if (AnimData.IsActive) {
    5.                     console.log("Chek1 - "+this.world.getEntityName(entity));
    6.                     let posi = this.world.getComponentData(entity,ut.UILayout.RectTransform);
    7.                     if (tilePos.length < tileCount) {
    8.                         tilePos[cont] = posi;
    9.                         cont++;
    10.                     } else {
    11.                         posi = tilePos[cont];
    12.                     }
    13.                     let dir = Math.floor(Math.random() * 4);
    14.                     switch (dir) {
    15.                         case 0:
    16.                                 posi.anchoredPosition.x = posi.anchoredPosition.x + 20;
    17.                             break;
    18.                         case 1:
    19.                                 posi.anchoredPosition.x = posi.anchoredPosition.x - 20;
    20.                             break;
    21.                         case 2:
    22.                                 posi.anchoredPosition.y = posi.anchoredPosition.y + 20;
    23.                             break;
    24.                         case 3:
    25.                         case 4:
    26.                                 posi.anchoredPosition.y = posi.anchoredPosition.y - 20;
    27.                             break;
    28.                     }
    29.                     if (!AnimPlay) {
    30.                         AnimData.IsActive = false;
    31.                         posi = tilePos[cont];
    32.                     }
    33.                     this.world.setComponentData(entity,posi);
    34.                 }
    35.             });
    36.             if (tileCount > 0) {
    37.                 tileRuns++;
    38.                 if (tileRuns == tileCount * 10) {
    39.                     tileCount = 0;
    40.                     AnimPlay = false;
    41.                 }
    42.             }
    43.         }
    The problem is that the program crashes with "posi is undefined" error, the tiles i want to move already exists, i used getComponent here as a try, but placing it in the for each gives the same error also I use other script to change the AnimData.IsActive and this script is set to execute after that.
    If I place a similar forEach before this only with a getComponent and a log in console it works.