RequiredComponent with interfaces can create a nullreference exception
See original GitHub issueSummary
Adding a component to a gameobject with a RequiredComponent attribute that has a interface as type will result in a exception if that gameobject does not have a component with that interface. It seems to attempt to make a instance of that interface which is not possible since its a interface.
A better more clearer error message is needed than a nullreference exception. It should be clear to the user that you cannot add this component to a gameobject if that gameobject does not have a component that implements the required interface.
How to reproduce [Bugs]
- Add the following code:
public interface ITest { }
[RequiredComponent(typeof(ITest))]
public class Test : Component { }
-Try adding the Test component to a gameobject that does not have a component that implements ITest. -Profit
Workaround [Bugs]
- Just ignore the error
Attachments
The error: [Edit] Error: NullReferenceException: Object reference not set to an instance of an object. CallStack: at System.Object.GetType() at Duality.Editor.UndoRedoActions.CreateComponentAction.SetupComponentForEditing(Component cmp) in c:\projects\duality\Source\Editor\DualityEditor\UndoRedoActions\CreateComponentAction.cs:line 108 at Duality.Editor.UndoRedoActions.CreateComponentAction.Do() in c:\projects\duality\Source\Editor\DualityEditor\UndoRedoActions\CreateComponentAction.cs:line 72 at Duality.Editor.Plugins.SceneView.SceneView.CreateComponent(TreeNodeAdv baseNode, Type cmpType) in c:\projects\duality\Source\Plugins\EditorModules\SceneView\Modules\SceneView.cs:line 514 at Duality.Editor.Plugins.SceneView.SceneView.newToolStripMenuItem_ItemClicked(Object sender, EventArgs e) in c:\projects\duality\Source\Plugins\EditorModules\SceneView\Modules\SceneView.cs:line 1531 at AdamsLair.WinForms.ItemModels.MenuModelItem.RaisePerformAction() in c:\Stuff\svn\Projects\AdamsLair.WinForms\WinForms\ItemModels\MenuModelItem.cs:line 318 at AdamsLair.WinForms.ItemViews.MenuStripMenuView.viewMenuItem_Click(Object sender, EventArgs e) in c:\Stuff\svn\Projects\AdamsLair.WinForms\WinForms\ItemViews\MenuStripMenuView.cs:line 306 at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (12 by maintainers)
Top GitHub Comments
Okay, I think I have something that works pretty well. First, here is the class setup:
And the results:
In the failure case there is no exception thrown and no undo/redo action is available.
Done by @deanljohnson. Closing this.