Sign in to follow this  

organizing code files in UE4 (C++)

This topic is 677 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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()

Edited by Sidd

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

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 

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

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. 

Edited by Syntac_

Share this post


Link to post
Share on other sites

This topic is 677 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this