I need to gather a lot of information about the environment on an action. Things like the position of the character, if it died, it’s position, position of some of the element in the level and so on. I would like to know what is the best way to implement that kind of thing and where ?
For me there is two solutions but maybe there is more and I would like to know about it.
Send continuous information to the game mode into a structure that will hold the information I need. On the action, do whatever I need with this structure of data.
Create a dispatch event like GatherInformation in the game mode BP. Each object that I need the information from can bind to that event and send them when the action fires up.
What do you think ? Should I do that we game mode ? Any better way to do that ?
dispatcher doesn’t seem to be a good idea.it’s 1 actor sends information to multiple actors.you could probably create some function s or events in game mode.and when player or other actors died.just get the game mode from actors and send location to game mode.or do you mean you need to get actors location every tick,that case I guess you can find a way to directly communicate with the actor.
Hello, thanks for you answer. It is not only actor position or whatever it can be anything else but yeah it would be on every tick which seems to me that it would overload a lot the game.
But I think I can counter that because I would like to gather information each time there is an input by the controller. So it would mean that on any input from the controller, I send a notification to every components to push their information to the game mode and then on a specific action, use the data ?
Well,that case the dispatcher should be better.create a dispatcher in game mode,and every time receive an input,call that dispatcher,boardcast to every existing actors.
Because first time I might misunderstood you purpose.and about interface I think it might not suit here.because you have to find a way to get those actors first in order to call their interface.interface is just a function that doesn’t need casting.with dispatcher you don’t have to worry about getting the actors.actors can get game mode and bind the dispatcher at their begin play.
but most important.these are my opinions.you don’t have to 100%trust me.because I don’t know if I’m 100% correct.
Hi @pezzott1, can you elaborate on the component ? I was thinking of the GM because it’s accessible in every other blueprint. Meaning that it’s pretty easy to send data to it.
On an input from the server I need to send a bunch of data from the level environment. This will be use for a neural network on the server side to calculate the next action.
The thing as I explain is that I want the flexibility to tell which component needs to send the data.
On the action I need to collect the data and send the data or send the data already collected.
For gathering the info you could create a subsystem inherited from game instance and use:
// Listens when world starts.
FWorldDelegates::OnPostWorldInitialization.AddUObject();
// Listens when actor is added to world.
FWorldDelegates::OnWorldInitializedActors.AddUObject();
// For async levels (have not personally tested this)
FWorldDelegates::LevelAddedToWorld.AddUObject();
On each callback check if the actor has UMyGatherComponent (the custom base component I mentioned above) to capture their pointers to then gather the info.
I cant help with replication, though. I would assume this custom subsystem will have all the logic since its created before the level and persists until the program is closed.
Thanks for the reply! I just watched the video. It seems that I can use the saving part to serialize my data to my server using a socket. I can serialize all the actor that has an interface to gather the information and so on. I think it can be great!