In my project I’m spawning actors at runtime with essentially an actor spawning gun. Imagine I spawn an NPC, then after this a UI pops up with fields for entering information about the NPC such as backstory and wealth, name and other things like what weapons it has.
I’ve been trying to work out how this UI can grab data from the last spawned actor (NPC) and enter new information about it where it will be saved. All of these actors seem arbitrary so I’m unable to just do ‘get all actors of class’ because I still can’t get the last one created and assign that one specifically this new data.
Will there ever be a scenario where two or more NPCs show the UI pop-up simultaneously?
What exactly is stopping you from creating the widget right after spawning an actor? Could that work? Or (relating to the 1st question), why not have the spawned actor create a widget for itself? This makes comms a breeze.
Hi, first scenario will never happen. Second scenario is already happening. The NPC spawns the UI form to pop up. The issue I’m having is putting that data in the form and have it apply to the NPC actor specifically.
So to extend on this, the process is I spawn the NPC with my NPC spawn gun. The NPC then spawns the widget for me to fill out then I press confirm and the widget is removed from parent and I’m left with the NPC.
Ideally that NPC then takes data from that form and becomes the variables I’ve just set it including name and such. However these variables also need to be saved to some kind of data table which I can export out as a .txt or something at runtime,
The project is quite interesting if not slightly convoluted
I’ve been looking at the plugins which will send this data to a CSV file. It all needs to be saved and send to a server where the CSV is incorporated into the database and that will be used for new instances of the game with these premade NPC’s based on the users creations.
Experimental for sure but it sounds cool.
I will give your solution a try and see if I can manage to get it working.
Otherwise how about the other way around?
If I have the form first, fill it out which then saves it as a data asset/ data table or something and the NPC which is spawned after confirmation takes on the properties of this data?
edit: Also you are blazing fast at prepping these blueprint screenshots. You’re brilliant
Not in the widget, they’re too volatile. If this is supposed to work as a central database of sort, consider one of the framework classes - the Game Mode could work. Anyone can access it any time. But you could keep it in the gun, too if that’s more convenient.
This seems like a good solution I think I’ll go with this way around. Yes it’s supposed to work as a central level-based database. The level itself will hold the data, so if someone else downloads the level they will also have those NPC’s previously created spawned there with the correct data. Ofcourse all of this data needs to be saved out to a CSV on a central server so I’ll work that bit out.
Rather than game mode, maybe something more level-based rather than global. Would casting to an actor in the world be a bad idea to send/ retrieve data from for each NPC?
I’ve since refined the project and I think I can more clearly explain what needs to happen.
As it currently stands I am using the input game mode + UI type system to control and interact with both the 3D world and UI elements.
It goes like this:
Click Create button which pops up a form for data entry, while simultaneously equipping my pawn with a ‘spawn npc’ gun.
The data I enter into this form now transfers to the variables of the spawned NPC. So if I enter into the form that this NPC has a red shirt, spikey hair and boots it will spawn with those traits.
I need this form to store itself as an editable item that I can access via my UI
When I change the data of this form, it needs to update the associated NPC
Do you know how I should create that bond between the form and the NPC? like ‘Form 1 is responsible for NPC 1’ at all times, at runtime and accessible through clicking it in my saved forms box in the UI. If I click ‘form 1’ then I should be able to immediately edit the details, click complete and it will update my NPC.
Is this a thing?
I think if I know how to create this association or bond/ link then I can do the rest myself such as the form appearing in the UI in an ever updating list of spawned NPC’s.
Edit:
Perhaps what should happen is that there are editable parameters on the NPC itself. So if I click the NPC to select it at runtime, the params appear in the menu and I can update them directly and apply them. I can send this data out to a CSV for later use. Do you think that might be a better idea?
Use Event Dispatchers to communicate between the UI form and the spawned NPC. Probably the cleanest solution in which the NPC does not even know the form exists. There may be no need to manually reference the forms since they’re supposed to persists in the UI.