Search Unity

Feedback Exotic forloop transform.childCount bug

Discussion in 'Scripting' started by StarBornMoonBeam, Apr 22, 2023.

  1. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    a rare 3 digit integer has appeared
    Underscore.png

    Code (CSharp):
    1.  
    2. int CC = BOARD.childCount;
    3. for (int x = 0; x < CC; x++)
    4. {
    5.       Debug.Log(CHESS + " " + CHESS.HEAT_MAP.Count + "" + x + " " + BOARD.childCount);
    6. }
    7.  
    The info shown here might be a little confusing. But it shows that reference to CC (child count) is 64. but the forloops x iterator. displays 039;

    So its obviously not formatted back end. or a rare type of bug. I don't usually obtain a transforms child count this way so I don't usually encounter this type of bug. I didn't file the post as a bug yet wanted to see what others make of it. Or see if anyone else had experienced anything like it.

    Have you ever seen anything like it?

    I'l just explain once more;
    The Boards child count is 64.
    for looping that child count returns values in unformatted 0 + index and eventually a null reference lol :)

    Its pretty funny, but, any idea why?
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,927
    If you just
    Debug.Log(x)
    what do you get?

    I'll note there's no space before x and
    CHESS.HEAT_MAP.Count
    so are you just getting a 0 appended before it?
     
    Bunny83 and StarBornMoonBeam like this.
  3. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    an expected value without a zero. I'll dig around some more. I may have a legit null reference somewhere. Stops around 39 just debugging the x. So i'll confirm nothing is up at 39 before continuing.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,927
    Yeah pretty sure you just mislead yourself by forgetting to put a space before x.
     
  5. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    Yes thanks Spiney i knew it was stupid;

    See because generating my heat map takes a few frames to establish the 8*8 grid, after each turn, or inbetween turns i should say. Sometimes the move is viable before the heatmap has established. The Heatmap is only for the AI see, and for Check Vetting of the royal piece. So the list was partial or zero while firing. So the fact 039 is returned is inconsequential and is something to do with the long multi-data debug habit I have. But ultimately it is still considered 39; value. just displayed as 039.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    I am curious why you would think that a basic read-only property on such as fundamental Unity thing would be a bug as opposed to your script. I feel thinking like this can stop you from debugging your own code correctly. :)

    I always assume it's my code and verify the Unity side using another code check before making any decisions. Maybe not so on huge complex things but for fundamental stuff it's different.
     
  7. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    It almost did stop me from debugging correctly. But it was laughable the whole time so at the back of my mind I knew it was just something stupid.
     
    MelvMay likes this.
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    I mean, I've been guilty of shouting "What the heck Unity" only to go make a drink, come back and quickly realise my mistake which was mostly that I've been staring at the screen too long without a break! :)
     
    MaskedMouse and MousePods like this.
  9. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    As we are in the game of anticipating problems coding in ways to avoiding problems. When it seems a problem arises in the structure of the program we use it can cause temporary haywire to our plans.

    check.gif
    I managed to achieve my plan anyways. See the heat map establishes at a quick interval. Sometimes I click on a unit, before it established, and generate movement options by action of selected unit. So I made sure my clicks cant function during heat map generation. In the above the queens cannot move to other tiles (not currently highlighed), they only have movement options available for capture or block of the white queens line of sight.

    So I managed to achieve what I wanted in the end. Enforcement of the player to resolve the check issue.