Best way to let several classes share one object
Hello! I was wondering if there were any parent class for a class that will only do one specific job and then relay the results to another class. I've found alot of cool and usable parent classes and was thinking there might be one for this as well.
The Problem: I'm currently having an actor class act as this kind of thing, I have a MovementCalculator-actor that I put in the game world, then classes who will use this MovementCalculator-actor have a pointer to it, during their BeginPlay() it will find the actor in the game world and start pointing to it.
Then to use it, for example I have units, who, when clicked, asks the calculator to calculate their movement, and then I have a Gameboard that reads all the movements calculated and activates the respective squares.
Now I was wondering if there were any other way in Unreal Engine to accomplish this without using actors, also preferably without making the entire class static, also no singletons.
Sorry if the English used is not perfect, I've been coding for a while and I'm a bit tired.
With state i mean, does the movement speed object store any variables in it that change during gameplay and influence movement? Looking at your previous answer this is not the case. So my recommendation is to make a function library which implements these functions. If you do need state i suspect you should store the state in either the gamemode or gameinstance depending on when you need it. The function library can easily find those if you pass in the actor for which you need a movement calculation.
answered Dec 11 '15 at 10:01 PM
Does this MovementCalculator-actor keep any state? If the answer is no would just advise to make a blueprintlibrary of it which all objects can call when they need to.
answered Dec 11 '15 at 09:33 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here