Facepunch / sbox-issues

175 stars 12 forks source link

"TypeLibrary could not find ComponentName" on saving a prefab #4162

Closed yuberee closed 8 months ago

yuberee commented 9 months ago

Describe the bug

Getting this error:

   at Sandbox.Component.Serialize(SerializeOptions options)
   at Sandbox.GameObject.Serialize(SerializeOptions options)
   at Sandbox.GameObject.Serialize(SerializeOptions options)
   at Sandbox.Scene.Serialize(SerializeOptions options)
   at Sandbox.PrefabScene.Save()
   at Sandbox.SceneExtensions.Save(Scene scene, Boolean saveAs)
   at SceneEditorMenus.SaveScene() in C:\Program Files (x86)\Steam\steamapps\common\sbox\addons\tools\code\Scene\SceneEditorMenus.cs:line 12
   at InvokeStub_SceneEditorMenus.SaveScene(Object, Object, IntPtr*)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Sandbox.MethodDescription.Invoke(Object targetObject, Object[] parameters)
   at Editor.MenuAttribute.<>c__DisplayClass29_0.<Register>b__0()
   at Editor.Option.OnTriggered()
   at Editor.Option.InternalTriggered()
   at Managed.SourceTools.Exports.Editor_Option_InternalTriggered(UInt32 self)
   at Sandbox.EngineLoop.RunFrame(CMaterialSystem2AppSystemDict appDict, Boolean& wantsQuit)
   at Sandbox.SourceEngineApp.RunFrame() in C:\build\_work\sbox\sbox\engine\Launcher\SourceEngineApp.cs:line 48
   at Sandbox.SourceEngineApp.RunLoop() in C:\build\_work\sbox\sbox\engine\Launcher\SourceEngineApp.cs:line 39
   at Sandbox.Program.LaunchGame() in C:\build\_work\sbox\sbox\engine\Launcher\Launcher.cs:line 93
   at Sandbox.Program.Main() in C:\build\_work\sbox\sbox\engine\Launcher\Launcher.cs:line 58

When I try to save a prefab containing a custom component. The component itself is pretty shrimple, it's just a few lines long. Manually saving does nothing, as soon as I close and reopen the prefab the changes are not there at all.

To Reproduce

  1. Pull https://github.com/Small-Fish-Dev/cat_harvest/
  2. Edit prefabs/planted_cat
  3. Add the Harvestable Cat component
  4. Save

Expected behavior

Correctly save

Media/Files

https://github.com/sboxgame/issues/assets/59583743/713cb313-ae6d-49a9-9574-ea88271aeee5

Additional context

No response

handsomematt commented 9 months ago

I suspect the EditorTypeLibrary isn't populated with your custom component, could you try creating an editor folder and putting a dummy class in it.

yuberee commented 9 months ago

I have a test component and a test class image image

Inside of the Editor folder, but I noticed that when I save any of them the game compiles, even when it should throw an error up. Not sure if related.

Oddly enough I had no problem yesterday, but today I open the project to find that the prefab is missing the component and I encounter the issue again.

I pushed the changes with the test class and component on the repo.

garrynewman commented 8 months ago

Closing this one in favour of #4273