Download

Blueprint Scripting with Modules / searching for keyword

Hello!
I am searching for a keyword so I can search for this topic I want to learn, but not sure how to phrase it.

Usually now, I do everything through casting. Which is bad for modularity.
I have been messing a lot with Interfaces, but it’s still not there, the proper modularity.

Let’s say I have a ship. This ship has “modules”, that player can install. The ship is the brains of everything.
I’ll just throw in an example:
Now I install a gun, it takes ammo, and electricity. I install generator, it takes fuel, but adds electricity, which the gun can use. The ship is running out of fuel, so I add new upgraded fuel tanks. Engine needs upgrade, because when it broke, it stopped taking fuel from the fuel tanks, the generator stopped, and guns stopped working. After I upgrade the engine, it takes more fuel… Etc.

All of these “modules” need to communicate between one another, they shoudl be hot swappable, etc, request if other module has certain amount of resources, turn off other modules, but they can’t be directly “connected”.

How would you go about this? If you guys know what I mean? Is there some keyword in programming lingo that I can research? Modular blueprint scripting doesn’t return me much.
Thank you :slight_smile:

In a nutshell, to make them modular, you communicate between them with interfaces.

If you do it with casting and custom events, they ‘know’ about each other. It’s perfectly possible to be ‘modular’ here, but there is still a deep connection between the actors.

If you use an interface, it’s called on an Actor. It doesn’t care what kind of actor, the actor might not even implement the interface, it doesn’t care.

You see, no casting, no knowledge in one BP or the internals of another. The only access point you have is the interface.

You can build your spaceship like this. The only way each part works, is by communicating through interfaces. That’s it.

The only time this breaks down, is when you want to have one-many functionality, ie, event handlers.

At the moment, in blueprints, you have to know what kind of actor you’re binding to, and then it’s all blown.

But for the most part, yes, interfaces will get you there…

I think you should utilized the power of inheritance with your objects.

The solution would be to have a parent class (probably an Actor) that is, let’s say it’s called BaseModule.

The BaseModule has all the properties and functionalities that you will want in any generic module, such as, for example, health/taking damage, attachment points, weight.

Then, make subclasses of BaseModule, say “WeaponsModule”
and “BrainModule”. These would be more specialized for guns and controlling other modules, respectively.

Off of those, you could make classes for various guns, fuel tanks, etc.

ActorComponents would be used for defining a trait that could be applied to any module, like consuming/producing resources or crew capacity.

For resources, for instance, you would have components based off of the actor ActorComponent class that could manage resources by contributing to how much of the resource the module would consume or produce. Then, the Module itself could go through its ResourceComponents and add/subtract the resources from the ship itself.

Now, you won’t have to be worrying about casting very much, because you would just cast everything to BaseModule. You should use function overriding to define specialized behaviors of generic tasks.

This would be fully utilizing the power of Object Oriented Programming.

It’s not the only way to do it, but it sounds like the best way to me.

Hope it helps!

Hello guys and thank you for the answers.
I have started using interfaces and actor components - meaning I have fuel component, electricity component, etc, and each machine can then reuse multiple components :).
Thanks for the leads!