NetworkList - UnityException: EditorPrefsGetInt is not allowed to be called
See original GitHub issueDescribe the bug
UnityException: EditorPrefsGetInt is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'Bag' on game object 'Player'.
See "Script Serialization" page in the Unity Manual for further details.
Unity.Collections.NativeLeakDetection.Initialize () (at /Users/bokken/buildslave/unity/build/Runtime/Export/NativeArray/DisposeSentinel.cs:28)
Unity.Collections.NativeLeakDetection.get_Mode () (at /Users/bokken/buildslave/unity/build/Runtime/Export/NativeArray/DisposeSentinel.cs:41)
Unity.Collections.LowLevel.Unsafe.DisposeSentinel.CreateInternal (Unity.Collections.LowLevel.Unsafe.DisposeSentinel& sentinel, System.Int32 callSiteStackDepth) (at /Users/bokken/buildslave/unity/build/Runtime/Export/NativeArray/DisposeSentinel.cs:107)
Unity.Collections.LowLevel.Unsafe.DisposeSentinel.Create (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle& safety, Unity.Collections.LowLevel.Unsafe.DisposeSentinel& sentinel, System.Int32 callSiteStackDepth, Unity.Collections.Allocator allocator) (at /Users/bokken/buildslave/unity/build/Runtime/Export/NativeArray/DisposeSentinel.cs:101)
Unity.Collections.NativeList`1[T].Initialize[U] (System.Int32 initialCapacity, U& allocator, System.Int32 disposeSentinelStackDepth) (at Library/PackageCache/com.unity.collections@1.0.0-pre.5/Unity.Collections/NativeList.cs:141)
Unity.Collections.NativeList`1[T]..ctor (System.Int32 initialCapacity, Unity.Collections.AllocatorManager+AllocatorHandle allocator, System.Int32 disposeSentinelStackDepth) (at Library/PackageCache/com.unity.collections@1.0.0-pre.5/Unity.Collections/NativeList.cs:176)
Unity.Collections.NativeList`1[T]..ctor (System.Int32 initialCapacity, Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at Library/PackageCache/com.unity.collections@1.0.0-pre.5/Unity.Collections/NativeList.cs:120)
Unity.Netcode.NetworkList`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] values) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/NetworkVariable/Collections/NetworkList.cs:13)
Bag.PostNetworkVariableWrite () (at Assets/Scripts/Resources/Bag.cs:8)
To Reproduce Steps to reproduce the behavior:
- Use
public NetworkList<Item> items { get; } = new NetworkList<Item>(new List<Item>());
as class member - Open Unity Editor
- See error
Actual outcome No error
Expected outcome N/A
Screenshots
Environment (please complete the following information):
- OS: macOS
- Unity Version: 2021.1.24f1
- Netcode Version: 1.0.0-pre.2
- Netcode Commit: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/commit/bcef5b992c5414707ff48c95a48a113fd0e09ad3
Additional context N/A
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
NetworkList exploding with custom struct that works with ...
UnityException: EditorPrefsGetInt is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake ...
Read more >Class NetworkList<T> | Netcode for GameObjects | 1.2.0
Type, Name, Description. FastBufferReader, reader. The stream to read the delta from. Boolean, keepDirtyDelta. Whether or not the delta ...
Read more >UnityException: get_time is not allowed to be called from ...
I'm trying to make a method that prevents player from spamming Space key. using System.Collections; using System.Collections.Generic; using ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is a straightforward workaround, namely, to move the instantiation into your Awake function.
@ashwinimurt ashwinimurt why is this a won’t fix? Your docs are literally broken
Even following the advice to move the instantiation to Awake() I still have issues.
Link from Unity Docs - https://docs-multiplayer.unity3d.com/netcode/current/basics/networkvariable/index.html#synchronizing-complex-types-example