Simple composition question, how to group functions in new classes etc

Hey gang,
I’m currently planning to add some classes that work with the default pawn class to help decrease the clutter inside the pawn class member functions. Basically keeping functions that affect a certain specific aspect of the pawn’s behaviour grouped.

Currently I have the support class setup as an UObject and instance it in the pawn.h file (like UPawnSupportClass* pawnSupportInstance; ).

It seems as a c++ noob that there are a few ways to handle this kind of composition… so I am looking for some advice as to how and why to handle this.



are you trying to do something like this?

class EntityComponent


class APawnMovementComponent : public EntityComponent
	FVector Velocity;

class APawnTransformComponent : public EntityComponent
	FVector Location;

class APawnEntity
	EntityComponent* GetComponentByName(FString ComponentName);

	APawnTransformComponent* transformComp;
	APawnMovementComponent* movementComp;

Just a quick example, but is this what you asked?
And now you want to know how to handle the communication between your Pawn´s behaviour?

best regards

Hi, Thanks for your response I’ll clarify a bit:
I have pawn.h/cpp, and for sake of argument, if this game had eating, then I would have private UObject class Eating.h/cpp, so I then don’t need Eat(), HungerTimer(), Excrete() (jk) and SmellFoodNearby() as members of Pawn. Pawn doesn’t need to see any Eating variables, but will use Eating functions with Pawn data being passed to it via parameters (I think!).

Now I guess I could make Eating an actor component, but I could also just leave it as a private UObject class and create an instance inside of Pawn to use it. I just don’t know enough about c++ composition to make the proper decision here.

Let me know if you need more specific info.

Well, both creating a component and creating a UObject is in essence doing the same thing here. Only difference is that by creating a component you’re getting the built in component functionalities.

I’d create a DigestionComponent with the neccesary functionalities, then in my pawn class create a Upropperty DigestionComponent* and instantiate a DigestionComponent in the constructor. That way, you can fetch your functions directly from the objects that “know” about your DigestionComponent, but can also easily acces them from classes that don’t if you have your pawn referenced only as an UActor* by calling a FindComponent methods.

Ok cool, thanks for the insight!