CompareBaseObjectsInternal can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
How do we solve this problem?
Best regards,
Taufik
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To reproduce this error, I do the following:
- Clone the repo
- Checkout the vdevelop branch
- Open the project in Unity (I use version 4.6.0f3)
- Do the next steps in an empty scene, with the default MainCamera GameObject
- Confirm that there is no error by pressing Play
- Stop the game
- Select Main Camera GameObject and add EntityState PDU component by clicking on Component > DISUnity > PDU > Entity Info Interaction > Entity State
- Press Play
- The error should be logged in the console
- Press Play again to stop the game, the error should appear one more time in the console
The interesting thing is that if we remove the Entity State Wrapper Component from Main Camera GameObject and then press Play, the error still happens.
I also attached Unity Editor log for you to check.
The error is being caused by MonoBehaviourSingleton on line 17.
This is caused by the destructor attempting to destroy some objects using the MemoryManager class. This is all caused by the way I handle VariableParameters and similar data types. The Unity inspector does not support complex data types unless they inherit from Scriptable object.
For example if I have a base class A and my MonoBehaviour had a list of this base class then any classes that are added to the list which inherit from A will be converted to the base class version in the inspector. However if I inherit my base class from ScriptableObject then it works but I now have issues where I can only create, delete, compare etc the object in the main thread. So a destructor which is not always called from the main thread causes issues. The ScriptableObjects are not garbage collected, they must be destroyed (like C++).
I have tried a few different approaches before this method but I think I am going to scrap my current method in favour of using standard .net. This will make things much simpler and far less buggy however I will need to think of a way to allow the inspector to still work.
My initial thought is to simply add multiple lists to the PDU that have all the supported data types, instead of a single list to the base data type. Its not ideal but there are not actually that many data types to support. I will start making the changes soon(probably now).
Karl
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for the update! Sorry I haven't answered very quickly, our team is currently on site to do some testing on the hardwares.
I see, so the problem is due to the use of ScriptableObjects. I have not used them myself in the projects that I've done because I think they are not very intuitive. However I agree with you that using multiple lists are is not the most elegant way to show data in the inspector.
I have also made some minor changes to remove the error for the descriptor member variable in Fire & Detonation PDU in vdevelop branch.
Thanks,
Avi
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Karl,
I am getting a lot of the following error:
CompareBaseObjectsInternal can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
How do we solve this problem?
Best regards,
Taufik
Hi,
Can you send me your logs?
How can I repeat this error?
Karl
Last edit: Karl Jones 2014-12-09
Hi Karl,
To reproduce this error, I do the following:
- Clone the repo
- Checkout the vdevelop branch
- Open the project in Unity (I use version 4.6.0f3)
- Do the next steps in an empty scene, with the default MainCamera GameObject
- Confirm that there is no error by pressing Play
- Stop the game
- Select Main Camera GameObject and add EntityState PDU component by clicking on Component > DISUnity > PDU > Entity Info Interaction > Entity State
- Press Play
- The error should be logged in the console
- Press Play again to stop the game, the error should appear one more time in the console
The interesting thing is that if we remove the Entity State Wrapper Component from Main Camera GameObject and then press Play, the error still happens.
I also attached Unity Editor log for you to check.
Thank you,
Avi
Thanks Avi. I'll take a look at it tonight.
Karl
Last edit: Karl Jones 2014-12-09
Hi Avi,
The error is being caused by MonoBehaviourSingleton on line 17.
This is caused by the destructor attempting to destroy some objects using the MemoryManager class. This is all caused by the way I handle VariableParameters and similar data types. The Unity inspector does not support complex data types unless they inherit from Scriptable object.
For example if I have a base class A and my MonoBehaviour had a list of this base class then any classes that are added to the list which inherit from A will be converted to the base class version in the inspector. However if I inherit my base class from ScriptableObject then it works but I now have issues where I can only create, delete, compare etc the object in the main thread. So a destructor which is not always called from the main thread causes issues. The ScriptableObjects are not garbage collected, they must be destroyed (like C++).
I have tried a few different approaches before this method but I think I am going to scrap my current method in favour of using standard .net. This will make things much simpler and far less buggy however I will need to think of a way to allow the inspector to still work.
My initial thought is to simply add multiple lists to the PDU that have all the supported data types, instead of a single list to the base data type. Its not ideal but there are not actually that many data types to support. I will start making the changes soon(probably now).
Karl
Ok all done. The entity state pdu should work with no errors now.
I have not finished making changes to the fire and detonation PDU yet so the descriptor field is not shown in the inspector at the moment.
K
Hi Karl,
Thank you for the update! Sorry I haven't answered very quickly, our team is currently on site to do some testing on the hardwares.
I see, so the problem is due to the use of ScriptableObjects. I have not used them myself in the projects that I've done because I think they are not very intuitive. However I agree with you that using multiple lists are is not the most elegant way to show data in the inspector.
I have also made some minor changes to remove the error for the descriptor member variable in Fire & Detonation PDU in vdevelop branch.
Thanks,
Avi