CookieBadger/assetplacer-docs

AssetPlacerPersistence throws NullReferenceException in Process Loop

Closed this issue · 10 comments

I have a game I am working on and when I enable it, I gets this error repeated in the process creating thousands of errors:

modules/mono/glue/runtime_interop.cpp:1303 - System.NullReferenceException: Object reference not set to an instance of an object.
     at AssetPlacer.AssetPlacerPersistence.StoreSceneData(String key, Variant value) in /mnt/Productivity/Gamemaking/Godot/Projects/PDCEscape/addons/assetplacer/AssetPlacerPersistence.cs:line 102
     at AssetPlacer.SpawnParentSelection.SetSpawnParent(Node node) in /mnt/Productivity/Gamemaking/Godot/Projects/PDCEscape/addons/assetplacer/SpawnParentSelection.cs:line 107
     at AssetPlacer.SpawnParentSelection._Process(Double delta) in /mnt/Productivity/Gamemaking/Godot/Projects/PDCEscape/addons/assetplacer/SpawnParentSelection.cs:line 54
     at Godot.Node.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Node.cs:line 1807
     at AssetPlacer.SpawnParentSelection.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret) in /mnt/Productivity/Gamemaking/Godot/Projects/PDCEscape/Godot.SourceGenerators/Godot.SourceGenerators.ScriptMethodsGenerator/AssetPlacer.SpawnParentSelection_ScriptMethods.generated.cs:line 89
     at Godot.Bridge.CSharpInstanceBridge.Call(IntPtr godotObjectGCHandle, godot_string_name* method, godot_variant** args, Int32 argCount, godot_variant_call_error* refCallError, godot_variant* ret) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/CSharpInstanceBridge.cs:line 24

I am using Godot 4.0.3.mono.stable on Arch linux. In addition to this plugin I am using the beta of Dialogic, destructibles c# and the official Godot Git plugin. The menu appears and seems to work even with this error, but none of the added items have proper images, they just have the godot thumbnail. If you need more information please let me know!

Hey Zach, thanks for taking the time to report this issue, I am looking into it.
I tried installing Dialogic, and saw no interaction so far between the two plugins.
From your error messages, it seems like the Persistence instance is not properly initialized. May I ask you, if there is any error different to this one, right at the beginning? I imagine, that something goes wrong, before it produces all these issues.
Also, would you mind sending me the configuration of your .csproj file?

For sure! This is as much as I was able to copy from the start:https://gist.github.com/ZachAR3/3362ddc4d5fbb3b5fd7f51300389c87f

And this is my .csproj:

<Project Sdk="Godot.NET.Sdk/4.0.3">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>
</Project>

I have tried rebuilding and regenerating my C# solution, and sometimes it will fix the errors as long as I don't close it, but nothing seems to fix the thumbnail issue. I tried on a clean project and I don't have this issue so it's some weird interaction between either the addons or something it can't handle in my project.

Thanks for the log, this helps.

Cannot open file 'res://addons/AssetPlacer_1.0.1_Godot_4.0.x/assetplacer/AssetPlacerPluginData.cs'.
  Failed to read file: 'res://addons/AssetPlacer_1.0.1_Godot_4.0.x/assetplacer/AssetPlacerPluginData.cs'.
  Cannot load C# script file 'res://addons/AssetPlacer_1.0.1_Godot_4.0.x/assetplacer/AssetPlacerPluginData.cs'.
  Failed loading resource: res://addons/AssetPlacer_1.0.1_Godot_4.0.x/assetplacer/AssetPlacerPluginData.cs. Make sure resources have been imported by opening the project in the editor at least once.
  scene/resources/resource_format_text.cpp:174 - user://.assetPlacer/data.tres:6 - Parse Error: [ext_resource] referenced non-loaded resource at: res://addons/AssetPlacer_1.0.1_Godot_4.0.x/assetplacer/AssetPlacerPluginData.cs
  scene/resources/resource_format_text.cpp:735 - user://.assetPlacer/data.tres:6 - Parse Error: [ext_resource] referenced non-loaded resource at: res://addons/AssetPlacer_1.0.1_Godot_4.0.x/assetplacer/AssetPlacerPluginData.cs
  Failed loading resource: user://.assetPlacer/data.tres. Make sure resources have been imported by opening the project in the editor at least once.
  Error loading resource: 'user://.assetPlacer/data.tres'.

The first thing to note is, that you should have the assetplacer folder directly inside your addons folder, otherwise, some file paths might fail. It should not be wrapped in an AssetPlacer_1.0.1_Godot_4.0 folder. Second of all, make sure that, before enabling the plugin, you click the build button on the top right, and that the build process concludes without errors.
Please let me know if the plugin works for you then.

It's not in res://addons/AssetPlacer_1.0.1_Godot_4.0.x/assetplacer/ it's in /mnt/Productivity/Gamemaking/Godot/Projects/PDCEscape/addons/ or res://addons/assetplacer. It must be the same Godot bug I have experiences before, where if you enable an addon then uninstall to change directories the .Godot folder doesn't update. I will try deleting my .Godot and see if the refreshed directory fixes it.

Hell, no matter what I do godot refuses to aknowledge the new path. I have tried deleting the .Godot folder after disabling and uninstalling the plugin, rebuilding, regenerating c# solution and yet the error always refers back to the original directory from before I properly moved it into the folder.

did you try closing the Godot Editor, and then deleting the .godot folder? Then it should regenerate everything. Also, I think the deleting the mono folder inside .godot should suffice.

did you try closing the Godot Editor, and then deleting the .godot folder? Then it should regenerate everything. Also, I think the deleting the mono folder inside .godot should suffice.

Yup, steps I tried to be thorough:

  1. Disable plugin in Godot
  2. Remove any mention of it from .Project file
  3. Delete .Godot folder
  4. Delete assetplacer addon from addons
  5. Relaunch Godot and the project
  6. Wait for regeneration
  7. Build
  8. Enable assetplacer
  9. Same errors still appear looking in /res://addons/AssetPlacer_1.0.1_Godot_4.0.x/assetplacer/

I have even used KFind to search through every file in my project for the path and none of them mention it.

I FOUND IT, you have a save file placed here:~/.local/share/godot/app_userdata/ProjectName/.assetPlacer/data.tres that has a reference to the script location in the first line, This is the corrected version since I forget to copy before regenerating, but the file locations in the top used to be set in the AsssetPlacer_1.0.1 folder:

[gd_resource type="Resource" load_steps=4 format=3]

[ext_resource type="Script" path="res://addons/assetplacer/SceneData.cs" id="1_72fva"]
[ext_resource type="Script" path="res://addons/assetplacer/AssetPlacerPluginData.cs" id="1_ht651"]

[sub_resource type="Resource" id="Resource_7yvs3"]
script = ExtResource("1_72fva")
data = {
"plane_positions": PackedFloat32Array(0, 0, 0),
"snap_offset": Vector2(0, 0),
"spawn_parent_path": NodePath(".")
}

[resource]
script = ExtResource("1_ht651")
sceneData = {
"res://Scenes/World/SceneChanger.tscn": SubResource("Resource_7yvs3")
}
globalData = {}
showLicenseOnStart = true

Edit: Regenerating this also fixed the thumbnail issue.

Oh, I understand, so in order to properly regenerate your project, the stored userdata needs to be removed as well. I will see if I can implement a fix, such that this file is reloaded automatically, in case it references an invalid path.
For now, I am happy that you could solve your issue.

Oh, I understand, so in order to properly regenerate your project, the stored userdata needs to be removed as well. I will see if I can implement a fix, such that this file is reloaded automatically, in case it references an invalid path. For now, I am happy that you could solve your issue.

Sounds good, I'm unsure if this is an issue you can solve on your side or if it's a Godot issue with auto-gen. If it's Godot side feel free to message me and I will make a bug report or give you the info to create one with my logs and such. I appreciate the help!