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

Unity 5 script conversion error

Discussion in 'Scripting' started by Griffo, Mar 13, 2015.

  1. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    693
    Hi,

    After loading Unity 5 it gave me this error ..

    Cannot convert type `EchoGameObject' to `UnityEngine.GameObject' via a built-in conversion

    From this code ..

    Code (CSharp):
    1.       public GameObject Clone ( bool iactiveflag )
    2.     {
    3.  
    4.           GameObject newgo = UnityEngine.Object.Instantiate ( this ) as GameObject;
    5.        
    6.         newgo.layer                        = gameObject.layer;
    7.         newgo.GetComponent<Renderer>().sharedMaterial     = GetComponent<Renderer>().sharedMaterial;
    8.  
    9.         return ( newgo );
    10.     }
    From line 4, can anyone tell me how to correct this please, thank you.
     
  2. Roderyk

    Roderyk

    Joined:
    Mar 5, 2015
    Posts:
    75
    Can you show me the full script, as to know what this means?

    But first: Try changing UnityEngine.Object.Instantiate to Instantiate alone.
     
  3. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    693
    Roderyk thanks for the input, the code is from a very large script out of the plugin core framework off the asset store, so I'm not sure the developer would appreciate me posting all his script, I've asked the developer about this but as yet no response, I tried changing UnityEngine.Object.Instantiate to Instantiate alone but still the same error.
    Thanks.
     
  4. Roderyk

    Roderyk

    Joined:
    Mar 5, 2015
    Posts:
    75
    Well, in that case I think the error is linked to the typeof this.
    If you happend to come across this information, I think it would help.
     
  5. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    693
    I presume this is the script, should it not be this.gameObject?

    If I put this.gameObject it compiles ..
     
  6. Roderyk

    Roderyk

    Joined:
    Mar 5, 2015
    Posts:
    75
    Should be.
    The error is a Casting one.
    you could also use, gameObject alone, I believe. It's the same pointer.
     
  7. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    693
    OK, once again thanks for the input.