I’ve been trying for months to create a way to simulate electrical circuits. I’ve tried so many different ways, but this is what I currently have.
Circuit Board actor has components attached to it that are the elements (ex: sources, resistors, ground, etc). Circuit Board actor has an array of connection structures which describe element connections (which component’s terminal to which component terminal). Every circuit element has a terminal map, integers as keys, with an energy struct that holds voltage and amperage as values.
Here is an organized way to explain this:
All energy flow and actions should take place on the circuit board blueprint, the component is just a data holder. I’m having trouble simulating the flow of energy from component to component. I usually use Set Members in S_Energy on each terminal for each connection. Am I going about this all wrong? If anybody can give some suggestions or ideas it would be greatly appreciated.
Here are some sites I use for refrences
I have a general understanding (about 2-3 years) of electronics, C++/C# and blueprints experience.
Oh man wish you had an answer for this, only thing i have been able to create is a generator that when on allows you to turn on/off anything in a boxtrace radius that has a power tag.
Im more versed in dc electronics than blue prints. And im not sure how youve structured your code But if i were thinking like i do.
Complicated Electrical circuits are lots of simple math problems like divide voltage and resistance to get current. And formulas to keep up with capacities, wattage, ext. and how all these affect the circuit can be summed up per circuit and saved as variables per circuit based on all components in the circuit.
I might make a macro for basic math equations. All that you would use, like circuit voltage(input) X component resistance(input) = circuit current(output) and then you could probably just place your macro and hook up a component and the circuit, then it would automatically grab the values of that component and run them with the circuits equation one by one to get the final values and use them for simulating.
In one blueprint that might be easy but i haven’t mastered casting so i dont know on that part. Ive just got the math theory.
Sounds like a fun experiment. If its what you’re talking about i might try to write my own test to see
I would have no experience on visualizing it but i got a few ideas. Like spawning and animated somethe between each component in the direction of flow.
we’re on the same page with inputs & outputs…
i think an electrical circuit simulator could be designed along the principles of “Flow-Based Programming”, which is what Blueprints is.
i’m not sure how this would be setup, but each electrical component would be a “node” and you connect them with wires, but the power source node doesn’t switch on unless it gets an input.
I mean, necroing a thread is always fun
Circuit simulation is a solved problem.
Each component connects each of its terminals to a “network” which is like a bit of wire with zero resistance/inductance/capacitance.
The CPU then solves the equation for the component using very small time steps (1-10 megaherts step rate is not uncommon) by iterating over all components current state, solving the differential equation for its transfer/response function, and updating the next step version of the component.
The only thing to look out for is that all components should READ the input from the current step, but WRITE the output to the next step, so you’ll typically need to double buffer this state.
Or you can just download an open source circuit simulator like NGSpice and drop that in. Seems easier
nice, i was looking for some kind of packaged solution, but as i couldn’t find one for UE i ended up here making a suggestion, which sounds like what you described. so, I’ll check out NGSpice, and search github for C++ libraries to implement a simulator.
this got me thinking about generally implementing “flow-based programming” in-game, maybe as a plugin. i recently saw gameplay of a game about building a factory, weaving a web of conveyor belts and machines, and it struck me as an implementation of FBP as playable game logic. there are several types of (mini-)games that could be built as in-game objects representing custom nodes and connectors… electricity, plumbing, conveyors, train tracks, etc.
There is indeed a whole “simulation” sub-genre of games based on that paradigm, yes!
Satisfactory is a nice Unreal Engine based factory simulator; Factorio is the classic 2D based game in the same vein.
Most of the “sim city” / “cities skylines” type games use a similar system for water, electricity, and roads.
On Roblox, there are many “miner tycoon” type games that do something similar, one way or another.
And then there are Zachtronics games like SpaceChem and Opus Magnum and Shenzhen I/O and …
Anyway, NGSpice isn’t “integrated with Unreal Engine” but it is open source, and you can probably break into the library in an appropriate place, to configure it with the components/models you want, and run some number of simulation iterations per game frame. Most third party libraries can be made to work by starting them in another thread, and pushing a little message queue of some sort into the middle, where you can post a message from the game to read state out, or control how they otherwise run.