Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Transform child out of bounds

Discussion in 'Scripting' started by gleblola389, Sep 14, 2023.

  1. gleblola389

    gleblola389

    Joined:
    Sep 13, 2023
    Posts:
    6
    Hey guys! When I run this code, I have message "Transform child out of bounds". Can someone help me, please?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Wall : MonoBehaviour
    6. {
    7.     public GameObject block;
    8.  
    9.     private void OnTriggerStay2D(Collider2D other)
    10.     {
    11.         if(other.CompareTag("Block"))
    12.         {
    13.             Instantiate(block, transform.GetChild(0).position, Quaternion.identity);
    14.             Destroy(gameObject);
    15.         }
    16.     }
    17. }
     
  2. gleblola389

    gleblola389

    Joined:
    Sep 13, 2023
    Posts:
    6
    I can upload full code, if need
     
  3. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    711
    then i guess it has no children
     
    gleblola389 likes this.
  4. gleblola389

    gleblola389

    Joined:
    Sep 13, 2023
    Posts:
    6
    Shame, sorry, I`m idiot xDDDD
     
  5. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    711
    hey, you can wear the shame hat for an hour but frankly you may need to hand it back to others who deserve it more
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    The general process for what bugfinders suggests can be learned here:

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
     
    bugfinders likes this.