Search Unity

error CS0119: 'Object.GetInstanceID()' is a method, which is not valid in the given context

Discussion in 'Getting Started' started by pod11, Feb 10, 2019.

  1. pod11

    pod11

    Joined:
    Jan 6, 2019
    Posts:
    60
    Im trying to add a name to instantiated game object depending on its Id.
    rest of the code is good as im folowing tutorial, just trying to add this one bit and for some reason i'm getting this error:
    error CS0119: 'Object.GetInstanceID()' is a method, which is not valid in the given context

    Code (CSharp):
    1.    if(isFiring)
    2.  
    3.        
    4.         {
    5.             shotCounter -= Time.deltaTime;
    6.             if(shotCounter <=0)
    7.  
    8.        
    9.             {
    10.                 shotCounter = timeBetwenShots;
    11.                BulletController newBullet =  Instantiate(bullet, firePoint.position, firePoint.rotation) as BulletController;
    12.            
    13.                 newBullet.speed = bulletSpeed;
    14.                [B] newBullet.name = newBullet.GetInstanceID.ToString();[/B]
    15.             }
    16.        
    17.  
    18.         }
    How should i do it ?
     
    Last edited: Feb 10, 2019
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    newBullet.name = newBullet.GetInstanceID().ToString();
    Notice the () after GetInstanceID.
     
  3. pod11

    pod11

    Joined:
    Jan 6, 2019
    Posts:
    60
    That solved my problem , thank you.
    Could you explain me these brackets? what are these doing really?
     
  4. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    The parens are method invocation symbols. They're a basic construct of almost every modern language. I strongly suggest learning some basics of C# if you want to do game development with Unity.