Error when trying to include own C++ Class

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!

Plugins cannot access any game module: Plugins in Unreal Engine | Unreal Engine 5.1 Documentation

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

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.