C++ Project Generation
There are multiple ways to get custom C++ code into EZ. The best way is to create an engine plugin, because this way the code can be executed directly inside the editor. Additionally such a plugins can be hot reloaded to some degree.
EZ uses CMake for its build infrastructure. See this chapter about different ways to integrate your own project into the EZ build.
The most convenient way, however, is to let the editor create a stand-alone project for you. This way you get a CMake based project that only contains your code, but has all the necessary references set up to link against EZ and output its DLLs to the right folder.
One downside with this approach is that your solution does not contain the EZ engine sources. That makes it less convenient to search for existing functionality, look up code API docs and stepping through EZ code while debugging. However, if you want that, you can include the generated plugin as an external project into the EZ engine solution.
How to Generate a New Solution
Select Editor > Open C++ Project.... The following dialog will appear:
Currently the locations for where the C++ source is stored and where the project will be built are both hard-coded to be within the project directory.
Choose the desired MSVC solution version.
Press the Generate Solution button and wait for it to finish.
The CMake output is output in the Output window. In case of errors, please have a look here.
If everything went fine, you can open the project and compile the code.
The code has to be built for the very same build type that the editor is running in (Debug, Dev or Shipping), otherwise the editor won't be able to load the DLL. If the build fails because certain EZ DLLs are missing, you are most likely building the wrong build type. The same may be true if you do code changes, but running the game from the editor doesn't reflect those changes.
After compiling your new plugin for the very first time, you have to close the editor project and reopen it, for it to load the information properly. Due to automatic hot reloading this shouldn't be necessary later anymore, but it can still be necessary, for example when you add a new component type to your C++ code.
Opening an Existing Solution
If you have generated the solution before, the Open Solution button will be active right away when you open this dialog. In this case you don't need to generate the solution again.
Regenerating a Solution
If you have added or removed source files on disk, you need to regenerate the solution for those changes to show up in the Visual Studio solution. You have two options to do so:
- Run CMake yourself. For example you can use the CMake GUI app, point it to the plugin's build directory, and then Configure and Generate the solution at any point you like.
- Rerun Generate Solution from the dialog above. This will clear the CMake cache and fully regenerate the solution. Be aware that this resets all CMake options to their default values and often takes longer than strictly necessary.