Important Compiler Error

Create issue
Issue #61 new
Former user created an issue

Hey there, thanks a lot for this great tool!

But unfortunately I got this error message while I was trying to build:

Assets/X-UniTMX/Code/Map.cs(2684,79): error CS0619: UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(UnityEngine.GameObject, string, string)' is obsolete:Method is not meant to be used at runtime. Please, replace this call with GameObject.AddComponent<T>()/GameObject.AddComponent(Type).'

It seems to be a show stopper ...

Greetings, Jo

Comments (3)

  1. Leon Ho


    I ran into this same problem as well, did some research and managed to build my game with this. Hope it helps.

    // get the same assembly as the Map from X-UniTMX
    System.Reflection.Assembly asm = typeof(Map).Assembly;
    // get the Type from string name
    Type ComponentType = asm.GetType (obj.GetPropertyAsString(Property_AddComponent + c));
    // overload of AddComponent that takes a Type
    gameObject.AddComponent (ComponentType);

    Thanks to

  2. Guilherme Augusto Almeida Filo Maia repo owner

    Hey, you are probably using the "Unity2D" branch, which is not updated to Unity 5 yet. Try using the "trunkDev" branch, there were some changes regarding the code, but if you just use the component, there will be no problem. I didn't test this solution gave by @leon_ho, I'm not sure if System.Reflection is available to all build targets, but it's nice to know it is a possible solution.

  3. Juan Manuel Leflet Estrada

    The solution given by @leon_ho compiles correctly, but it fails when the custom property "add componentX" tries to find the component to add (at least it's not working for me):

    AddComponent asking for invalid type
    X_UniTMX.Map:ApplyCustomProperties(GameObject, MapObject) (at Assets/X-UniTMX/Code/Map.cs:2689)
    X_UniTMX.Map:AddPolygonCollider3D(GameObject, MapObject, Boolean, Single, Single, Boolean, Boolean, Boolean) (at Assets/X-UniTMX/Code/Map.cs:2411)
    X_UniTMX.Map:AddBoxCollider3D(GameObject, MapObject, Boolean, Single, Single, Boolean, Boolean) (at Assets/X-UniTMX/Code/Map.cs:1640)
    X_UniTMX.Map:GenerateBoxCollider3D(MapObject, Boolean, Single, Single, Boolean, Boolean) (at Assets/X-UniTMX/Code/Map.cs:1665)
    X_UniTMX.Map:GenerateBoxCollider(MapObject, Boolean, Boolean, Single, Single, Boolean, Boolean) (at Assets/X-UniTMX/Code/Map.cs:1739)
    X_UniTMX.Map:GenerateCollider(MapObject, Boolean, Boolean, Single, Single, Boolean, Boolean, Boolean) (at Assets/X-UniTMX/Code/Map.cs:2487)
    X_UniTMX.TiledMapComponent:GenerateColliders() (at Assets/X-UniTMX/Code/TiledMapComponent.cs:149)
    X_UniTMX.TiledMapComponent:OnLoadFinished(Map) (at Assets/X-UniTMX/Code/TiledMapComponent.cs:127)
    X_UniTMX.Map:ContinueLoadingTiledMapAfterTileSetsLoaded() (at Assets/X-UniTMX/Code/Map.cs:890)
    X_UniTMX.Map:OnFinishedLoadingTileSet(TileSet) (at Assets/X-UniTMX/Code/Map.cs:812)
    X_UniTMX.TileSet:BuildTiles(Int32) (at Assets/X-UniTMX/Code/TileSet.cs:322)
    X_UniTMX.TileSet:.ctor(NanoXMLNode, String, Map, Boolean, Action`1, Int32) (at Assets/X-UniTMX/Code/TileSet.cs:265)
    X_UniTMX.Map:Initialize(NanoXMLDocument) (at Assets/X-UniTMX/Code/Map.cs:748)
    X_UniTMX.Map:.ctor(TextAsset, String, GameObject, Material, Int32, Boolean[], Action`1, Int32, Boolean, Double, Double, JoinType, EndType, Single) (at Assets/X-UniTMX/Code/Map.cs:440)
    X_UniTMX.TiledMapComponent:LoadMap() (at Assets/X-UniTMX/Code/TiledMapComponent.cs:114)
    X_UniTMX.TiledMapComponent:Initialize() (at Assets/X-UniTMX/Code/TiledMapComponent.cs:94)
    X_UniTMX.TiledMapComponent:Awake() (at Assets/X-UniTMX/Code/TiledMapComponent.cs:86)

    More specifically, asm.GetType returns null when trying to find the type of the component.

  4. Log in to comment