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
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…
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!