Search Issue Tracker
By Design
Votes
1
Found in [Package]
1.7.8
Issue ID
UVSB-2379
Regression
No
ArgumentNullException when trying to check if EventHook == null
How to reproduce:
1. Open the user's attached project
2. Enter Play mode
3. Observe the Console
Expected result: There are no errors in the Console
Actual result: Console produces the "ArgumentNullException: Value cannot be null." error
Reproducible with: 1.7.8 (2021.3.4f1, 2022.1.5f1, 2022.2.0a16)
Couldn't test with: 2019.4.39f1, 2020.3.36f1 (No Visual Scripting version available)
Reproducible on: Windows 10
Note: Script that causes the error can be found in Assets/Scripts
Comments (2)
-
jeanedouard_unity
Aug 24, 2022 17:46
The user uses the following code that breaks :
EventHook m_eventHook;
void Start()
{
m_eventHook = new EventHook("DoWork");
EventBus.Register<int>(m_eventHook, DoWork);
}private void Update()
{
if (m_eventHook != null)
{
EventBus.Trigger(m_eventHook, 1);
}
}
But EvenHook is a struct and structs are value types. This means it cannot be null and when checking if the eventHook is null it falls back on a default implicit operator which is by design. If users want to check if the EventHook is null they must use the Nullable Value Types C#8 feature. Here is how the code should look like:EventHook? m_eventHook;
void Start()
{
m_eventHook = new EventHook("DoWork");
EventBus.Register<int>(m_eventHook.Value, DoWork);
}private void Update()
{
if (m_eventHook != null)
{
EventBus.Trigger(m_eventHook.Value, 1);
}
} -
SmartMediaNL
Jun 10, 2022 10:57
What happens is that the check to see if the EventHook is null will in turn (internally by Unity Engine) do its own even hook call with a string that is null resulting in the error thrown mentioned above.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- "InvalidOperationException: Trying to SetRenderAttachment on a texture..." exception is thrown when using the depth back buffer as an input attachment in Renderer Feature on Vulkan Graphics API
- [HDRP Wizard] Reload Window fails to reload the HDRP Wizard window
- [HDRP Wizard] Fix All button is not presented using the macOS system
- "InvalidCastException: Specified cast is not valid" is thrown when Generating Lighting with "Virtual Offset" enabled in APV, and a static Skinned Mesh Rendered with a Mesh Filter Component is in the Scene
- TMP material doesn't update when using Localized Property to change the font assets
Resolution Note:
The issue is in the user's project (see details in comments)