Use delegates or add dependencies between modules

Hi!

I’m using Visual Studio 2022 and Unreal Engine 5.4.4.

In a method of a class in module A, I need to call a method in a class in another module B to perform a calculation. This would be the only time I would need something from module B.

I was thinking of using a delegate or a pointer to functions to use this method of module B, rather than including module B as a dependency of module A.

Am I making my life too complicated, or should I just add this dependency inside module A?

By the way, I don’t know if I can use a delegate that returns a value.

Thanks!

could you use an interface?

The only thing I would not want to do is add another dependency between modules. But if it ends up being necessary, I would add it.

I suppose so. But I can’t see how I could use the interface.

Thanks!

well the point is you dont need a reference to the class in Module B, just implement the interface and pass it through as a UObject*

I’m looking for some example about how to do that. Do you know any?

sure but your original post was kinda vague, can you give an example of the function you’re trying to call?

im just about to log off though so may just be worth searching for interfaces

OR

you could use this method

but i think an interface is safer

1 Like

Sure, this one:

FTime CoordinateSystems::RightAscensionToHourAngle(const double DecAlpha, const double Longitude, const FAstroDateTime& Date)

FTime and FAstroDateTime are structs without methods.

heres info on how to create an interface

but are the structs dependent on Module B?

1 Like