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
-
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
- Prefab override popup is cropped/positioned incorrectly when more than one display is used and a higher display Scale is set
- Opening a dropdown on a small screen results in its instant closing when mouse cursor is pressed where the dropdown is going to be opened
- Only "ArgumentNullException: Value cannot be null" is displayed instead of all the actual errors when opening a project with numerous compilation errors
- MultiColumnListView and MultiColumnTreeView do not change selection on first input when focus is set by code
- SerializedProperty.DataEquals is returning false when SerializedProperty.EqualContents return true
Resolution Note:
The issue is in the user's project (see details in comments)