[Solved] Unity3d reports an error using the opencv plug-in: unsafe code may only appear if compiling with/unsafe.

Problem description

When using the opencv for unity plug-in, the error “assets \ opencvforunity \ examples \ advanced \ alphablendingexample \ alphablendingexample. CS (530, 17): error CS0227: Unsafe code may only appear if compiling with /unsafe. Enable “Allow ‘unsafe’ code” in the inspector for ‘Assets/OpenCVForUnity/EnoxSoftware.OpenCVForUnity.asmdef’ to fix this error.”

Solution:

There are two ways to modify:

1. Tools entry modification

Tools > on the upper side of the window; OpenCV For Unity > Check use unsafe code
as shown below:

However, if there may be no such entrance, use method 2

2. Modify asmdef file

The. Asmdef file is an assembly definition file. This method is also available in the error prompt
modify the file in the path of assets/opencvforunity/enoxsoftware.opencvforunity.asmdef. After selecting the file, check the allow ‘unsafe’ code option in the inspector window and click apply.


Read More: