Reputation: 492
Now, I have resource-consuming C# script, uses Unity API. If I try to write external library (due to performance reasons), can I access Unity3D API from C/C++ code (e.g. Physics.OverlapSphere or Physics.SphereCast functions)?
Upvotes: 2
Views: 2867
Reputation: 5844
No, you cannot. The Unity3d classes are only accessible to C# code. C++ plugins cannot call Unity3d functions. The only exception are rendering plugins, as described in here.
As a aside: The Physics functions are likely heavily optimized in the Unity engine, so if the main cost of your resource-consuming script comes from the usage of these functions, the gain would be minimal or even negative due to the need of marshalling the data for passing them to the C++ plugin and back. You can check this using the script profiler is you have the Pro version.
As another aside, you will likely get faster and better answers on https://answers.unity3d.com/, the dedicated Q&A site for Unity.
Upvotes: 3