fx-lange / unity-sketchapp-import

Unity plugin to import from Sketch 4 (via the FramerGenerator)
35 stars 7 forks source link

ArgumentException: The Object you want to instantiate is null. Unity 2017.2.0p2 #1

Closed davon92 closed 6 years ago

davon92 commented 6 years ago

Hello,

I've created a sample sketch document and exported it using framegenerator.app on a Mac in order to test the unity-sketchapp-import.

I have the Json 9.0.1 unity package and the sketchapp-import editor and prefabs in a unity 2017.2.0p2 project on a windows 10 PC. I drag in the image prefab then open the sketch import window and select the framegenerators exported layers.json file in the imported folder where the images folder also exist. I then select the image prefab and have also tried this with a canvas object and panel as suggested in the ReadMe.txt file and hit the import button. but all im left with

ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:238)

which referes to this code block;

 void Parse(JObject json,RectTransform parent, Vector2 parentPos)
    {
        string imagePrefabPath = "Assets/Import/Prefabs/Image.prefab";

        string name = (string)json["name"];

        //load prefab from assets
        Image imagePrefab = (Image)AssetDatabase.LoadAssetAtPath<Image>(imagePrefabPath);

        //instantiate
        //Image image = PrefabUtility.InstantiatePrefab(imagePrefab) as Image; //still linked to the prefab
        Image image = Instantiate<Image>(imagePrefab);
        ...
     }

//this line->being where the error occurs// Image image = Instantiate(imagePrefab);

All of the images are turn into sprites and imported but they are not arranged or grouped in the image prefab within the hierarchy to mimic the page.

would you happen to know of a reason that this may be happening or any theoretical solutions?

davon92 commented 6 years ago

Found the Answer this Line -> string imagePrefabPath = "Assets/Import/Prefabs/Image.prefab"; assumes that the image prefab is in this folder structure location but when downloding the github zip folder the prefab folder is not inside an Import folder. This information should be added to the Readme.

fx-lange commented 6 years ago

Hi @davon92, thanks for giving the package a try. I replaced the hardcoded path with a selection so it doesn't matter anymore where you installed and how you named it.

fx-lange commented 6 years ago

@davon92 the package is more in a experimental stage as you probably did notice. if you don't mind it would be interesting for me to know if it was helpful and how you used it.

davon92 commented 6 years ago

it was pretty good. Much better than having to eyeball align it myself after our sketch designer has already laid it out with perfect accuracy.

I did notice was that when the unity page is generated the main sketch file root group pivot was center to the bottom left of the canvas and so the child objects we're placed and anchored based on that objects location which was way off. The fix is easy enough, just drag all children out , re adjust the main group object and then re align the child group back inside.

The second thing is a question about potential feature. I'm wondering if it would be possible for updating page images if I say update the buttons or come copy or the layout as of now I don't see a way to update. Rather I must generate a new page. And the only issue with that may be that scripts may exist on some of those items. Which would be a pain to re address.

On Jan 30, 2018 5:42 AM, "Felix Lange" notifications@github.com wrote:

@davon92 https://github.com/davon92 the package is more in a experimental stage as you probably did notice. if you don't mind it would be interesting for me to know if it was helpful and how you used it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fx-lange/unity-sketchapp-import/issues/1#issuecomment-361553797, or mute the thread https://github.com/notifications/unsubscribe-auth/ANyBKDiNUAr5zyAf058l76PGwsSq6wsZks5tPvIVgaJpZM4RoRAJ .

fx-lange commented 6 years ago

Thanks a lot for the feedback, the second part is definitely something I planed to do next as staying in sync with the design is one of main goals of the workflow.