Closed dvpavlov-dev closed 1 year ago
@dvpavlov-dev Ok. I will take a look. Yeterday I made a PR to fix this issue. Maybe it was not enogugh.
Downloaded git, and with large files there is such an error. My code looks like this and there seems to be no error) I changed it back in 2022, as I write it. I have a pretty old version of the project, I didn't download it, but changed what I needed on my own, so I don't throw a fix, I don't know how well it will work with the changes that were and there's just no time for it)
and AddFills
private void AddFills(Node node, GameObject nodeGo)
{
var gradientGeneratorId = AssetDatabase.FindAssets("t:GradientsGenerator")[0];
GradientsGenerator gg =
AssetDatabase.LoadAssetAtPath<GradientsGenerator>(AssetDatabase.GUIDToAssetPath(gradientGeneratorId));
Image image = null;
if (node.fills.Length > 0f && nodeGo.GetComponent<Graphic>() == null)
{
image = nodeGo.AddComponent<Image>();
}
for (var index = 0; index < node.fills.Length; index++)
{
var fill = node.fills[index];
if (index != 0)
{
var go = InstantiateChild(nodeGo, fill.type);
image = go.AddComponent<Image>();
}
switch (fill.type)
{
case "SOLID":
var tmp = nodeGo.GetComponent<TextMeshProUGUI>();
if (tmp != null)
tmp.color = fill.color.ToColor();
else
image.color = fill.color.ToColor();
break;
default:
var tex = gg.GetTexture(fill, node.absoluteBoundingBox.GetSize(), 256);
string fileName = $"{node.name}_{index.ToString()}.png";
SaveTexture(tex, $"/{_importer.GetRendersFolderPath()}/{fileName}");
var sprite = ChangeTextureToSprite($"Assets/{_importer.GetRendersFolderPath()}/{fileName}");
image.sprite = sprite; // Проблемы NullReferenceException: Object reference not set to an instance of an object
break;
}
if (image != null)
{
image.enabled = fill.visible != "false";
}
}
}
Image image = nodeGo.GetComponent()==null)
image = nodeGo.AddComponent
Well, there is clearly something strange going on in your code, and you assign a value, and then checks if it is null)
@VladislavMm I don't have the error that @dvpavlov-dev described. Do you mean it may happen only with large figma frames/nodes? @dvpavlov-dev how did you install the plugin? If via package manager, try to remove Packages/package-lock.json file. Or please provide an example how to reproduce it.
@VladislavMm I don't have the error that @dvpavlov-dev described. Do you mean it may happen only with large figma frames/nodes? @dvpavlov-dev how did you install the plugin? If via package manager, try to remove Packages/package-lock.json file. Or please provide an example how to reproduce it.
Yes, very large projects, then this error is displayed if I use your code, everything works on mine, I sent what I changed in your code and everything worked fine.
@VladislavMm I don't have the error that @dvpavlov-dev described. Do you mean it may happen only with large figma frames/nodes? @dvpavlov-dev how did you install the plugin? If via package manager, try to remove Packages/package-lock.json file. Or please provide an example how to reproduce it.
I think I found the reason, it's in this, if you remove it, then this error comes out-
I click on Generate nodes and this error pops up:
In the code, the error is here:
I tried to download old works from Figma that used to always load, but now they don't load because of this error. I deleted the FigmaImporter folder and installed it back. Installed today the latest version that was on git.
I added this code: if (node.field != null) { Add files(node, node Go); } But it didn't help.
And I'm sorry, I made a mistake, I didn't have your problem either, it came out like this- NullReferenceException: Object reference not set to an instance of an object FigmaImporter.Editor.FigmaNodeGenerator.AddFills (FigmaImporter.Editor.Node node, UnityEngine.GameObject nodeGo) (at Assets/FigmaImporter/Editor/FigmaNodeGenerator.cs:153)
@dvpavlov-dev do this and show what gives you
Nothing, I don't have such a file
I can make it created dynamically if there is no instance. Or maybe I'll turn it into a usual class, not SO.
Nothing, I don't have such a file
Well, we found the problem)
It's funny, the bug was fixed when I downloaded the package through the package manager. Previously, I just downloaded the entire project from git, and moved the FigmaImporter folder to my project.
Now I entered the URL link into the package manager, he apparently downloaded the missing config and everything worked!
In any case, thanks for the help, anyone could have been in my place, so it's good that we created this topic and sorted out the error :)
@dvpavlov-dev Nice to hear that. I've pushed changes to prevent it in a future. So now, if it is missing, the instance of gradients generator will be automatically created.
When I click on Generate nodes, the following error appears:
IndexOutOfRangeException: Index was outside the bounds of the array. FigmaImporter.Editor.FigmaNodeGenerator.AddFills (FigmaImporter.Editor.Node node, UnityEngine.GameObject nodeGo) (at Assets/FigmaImporter/Editor/FigmaNodeGenerator.cs:145) FigmaImporter.Editor.FigmaNodeGenerator.GenerateNode (FigmaImporter.Editor.Node node, UnityEngine.GameObject parent, System.Collections.Generic.IList`1[T] nodeTreeElements) (at Assets/FigmaImporter/Editor/FigmaNodeGenerator.cs:109) FigmaImporter.Editor.FigmaImporter.GetFile (System.String fileUrl) (at Assets/FigmaImporter/Editor/FigmaImporter.cs:312) System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) (at <27586baf39bf4babbfd8a2caabe8e228>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <61c05f8d81804e929ff4198c5bcc7a62>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <61c05f8d81804e929ff4198c5bcc7a62>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <61c05f8d81804e929ff4198c5bcc7a62>:0)
I have launched both on new projects in Figma and on old ones that used to work. All projects have this error.
A week ago everything worked, but today this error appeared.