# Error when trying to include own C++ Class

**URL:** <https://forums.unrealengine.com/t/error-when-trying-to-include-own-c-class/767501>\
**Category:** Pipeline & Plugins\
**Tags:** include, unreal-engine, CPP, question\
**Created:** [February 9, 2023, 6:34pm UTC](https://forums.unrealengine.com/t/error-when-trying-to-include-own-c-class/767501 "2023-02-09T18:34:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ullriche](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ullriche](https://forums.unrealengine.com/u/ullriche)\
**Post date:** [February 9, 2023, 6:34pm UTC](https://forums.unrealengine.com/t/error-when-trying-to-include-own-c-class/767501/1 "2023-02-09T18:34:56Z")

</div>

Hey there,  
I’m working with CARLA, an open source Simulator for autonomous driving based on Unreal Engine 4.  
I’m not sure what exactly it is, but when I’m building it from source I get a Unreal Engine 4 Project With the Carla Plugin installed.

To my Problem:  
I’ve created a C++ class via the Unreal Engine Editor. The Menu point for creating a C++ class doesn’t show when I’m right-clicking in the Content Browser, so I had to create one via the File Drowdown menu.  
I only can created it in the following folder `carla\Unreal\CarlaUE4\Source\CarlaUE4`, with “carla” beeing the root folder of the Project.  
There I created 2 files, `TrackLayouter.cpp` and `TrackLayouter.h`, a class derived from the `AActor` Class.

I got it to work, I can spawn it into the world and works like I want it to.

Carla works with Sensors (RGB Camera, Depth Camera, etc…) and there is an official Documentation Entry explaining how to create your own custom Sensor.  
`https://carla.readthedocs.io/en/latest/tuto_D_create_sensor/`

When following that, you have to create a C++ class (named `ARailwayInvasionCamera`) inside following folder:  
`carla\Unreal\CarlaUE4\Plugins\Carla\Source\Carla\Sensor`.  
Inside that class I need to get a reference to my TrackLayouter class.

I tried including `../../../../../Source/CarlaUE4/RailwayLayouter.h` in the header file of `RailwayInvasionCamera.h`, but I get the error:

“`D:\BAI\carla\Unreal\CarlaUE4\Plugins\Carla\Source\Carla\Sensor\../../../../../Source/CarlaUE4/RailwayLayouter.h(16): fatal error C1083: Cannot open include file: 'RailwayLayouter.generated.h': No such file or directory`”

I tried to declare `class ARailwayLayouter;` in the beginning of the `RailwayInvasionCamera.h` and including `RailwayLayouter.h` in the cpp file, but I get the same error.

Does anyone know what I’m doing wrong?  
I tried rebuilding it with the `make rebuild` command of Carla and tried to delete the `.vs`, `Binaries` and `Intermediate` folders and the `.sln` and generating the Visual Studio Project files, but the error stays.

Hopefully somone knows how to fix that!

Thanks!

---

<div class="post-metadata">

**Author:** ![zeaf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zeaf/32/1108035_2.png) [@zeaf](https://forums.unrealengine.com/u/zeaf)\
**Post date:** [February 9, 2023, 8:35pm UTC](https://forums.unrealengine.com/t/error-when-trying-to-include-own-c-class/767501/2 "2023-02-09T20:35:53Z")

</div>

Plugins cannot access any game module: [Plugins in Unreal Engine | Unreal Engine 5.1 Documentation](https://docs.unrealengine.com/5.1/en-US/plugins-in-unreal-engine/#:~:text=customizing%20these%20files.-,Code%20in%20Plugins,-When%20generating%20project)

But you can link and include plugin code in your game module, so you can create the class in your game module, inheriting from the plugin’s class. You just need to make sure you list the plugin’s module as a public dependency module in your game’s `.build.cs` file

---

<div class="post-metadata">

**Author:** ![ullriche](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ullriche](https://forums.unrealengine.com/u/ullriche)\
**Post date:** [February 10, 2023, 12:26pm UTC](https://forums.unrealengine.com/t/error-when-trying-to-include-own-c-class/767501/3 "2023-02-10T12:26:14Z")

</div>

Thanks for the reply!

The Plugin CARLA has a PythonAPI which is used to control and spawn things while the editor is running. Via that I want to spawn the `RailwayInvasionCamera` class. Todo that I have to register it in `SensorRegistry.h`, which is located at `carla\LibCarla\source\carla\sensor`.

I tried your Idea (in a way) and moved the `RailwayInvasionCamera` files to `carla\Unreal\CarlaUE4\Source\CarlaUE4`, where `RailwayLayouter` is as well.

Now I don’t want to access a game module from a plugin. The error does not happen in the `RailwayInvasionCamera` file, but in the `SensorRegistry.h`, when trying to include `RailwayInvasionCamera`.

So I guess I have to, one way or another, access a file which is outside the plugin.  
I guess it will not work, by moving the `RailwayLayouter` to the plugin, since I probably would not be able to spawn it then. But I’m not sure.
