LizzyFox
Topic Author
Posts: 4
Joined: 02 Nov 2023, 12:14

Behavior.AssociatedObject in AttachableObject.OnDetaching is null (bug)

03 Nov 2023, 17:35

Hi there!

If we use AssociatedObject in custom Behavior.OnDetaching method we get NullReferenceException :(
For example:
protected override void OnDetaching()
{
	base.OnDetaching();
	AssociatedObject.PreviewKeyDown -= OnPreviewKeyDown; // NullReferenceException
}
Noesis GUI version is 3.2.2, Unity version is 2023.1.13f1.

Thanks in advance.
 
User avatar
sfernandez
Site Admin
Posts: 3013
Joined: 22 Dec 2011, 19:20

Re: Behavior.AssociatedObject in AttachableObject.OnDetaching is null (bug)

06 Nov 2023, 11:42

Hi, this issue is already reported here: #2730.
It is happening because the associated object is being destroyed and then OnDetaching is called.
While we fix it, you can just check if the associated object is null before using it.

Who is online

Users browsing this forum: Bing [Bot] and 2 guests