Advertisement

organizing code files in UE4 (C++)

Started by February 06, 2016 01:19 PM
3 comments, last by Syntac_ 8 years, 10 months ago

From what I can tell C++ Class templates (such as Character.h/Pawn.h) seem to include functions for camera and controller inputs. I get the impression that this is some kind of coding standard to make life easier for the user?

Is this true, and if so, will I encounter problems in the long run if I split up the functionality into several files?

An example is the AdvancedVehicle template in UE4:

vehicleCharacter.h

SetupPlayerInputComponent()

CameraStick()

CameraSettings()

ACharacter contains a camera and controller input because it'd assumed your character will be controlled by a person and due to that you'll want to see the character so the camera will be attached.

It doesn't have to be this way, you could have an independent camera which isn't attached to the character, or accept input in some other way.

Similarly a pawn has no camera or inputs because it's assumed a pawn is computer controlled e.g. by an AI controller.

Hope this helps!
Advertisement

Yeah that makes sense. It's just coming from a Unity and basic c++ background, I'd I want to split up the Characters functionality into several files in order to follow c++ and Unity standards.

A Typical C++ Class in UE4 (found in tutorials and templates):

vehicleCharacter.h

SetupPlayerInputComponent()

CameraStick()

CameraSettings()

I'd like to split it up like this:

vehicleCharacter.h

wheels()

suspension()

...

vehicleCamera.h

Camerastick()

Camera()

...

vehicleInputCtrl.h

OnHandbrakePressed()

OnHandbrakeReleased()

....

But I'm hesistating because in Unity the coding structure is directly reflected in the Editor. I am not sure if this is the case in UE4.

Anyways, I'll try to split up the files and see what happens :D

You do still split up the character into multiple files.

You need to visualise your character as a set of distinct components and then use composition to build your character from these as member variables.

For example in my own game the player character is composed from, amongst other things, a weapon component, inventory component, armour and shield component as well as some helper components such as the one that manages the minimap. All of these components are reusable and independent from the class they are a member of, so I could reuse a weapon component on an enemy pawn for example.

Each of these is its own class with its own header and CPP file, and can communicate with other parts of the engine via delegates.

Hope this helps!

The only need to split up code into different files is to aid in reducing dependencies. I hate it when people create lots of files for the sake of it.

This topic is closed to new replies.

Advertisement