Hi. First time posting. I’ve been trying to create a Dynasty system like in Crusader Kings 2 but I cannot figure out how to create a new variable and have it appear in an array without me adding it manually, as well as visually adding it to the widget blueprint images, shown here,
Hi, thanks for the response, unfortunately that method is manual and limited by the amount of elements I add myself, I want to create a system that adds them automatically so when a new child is born it creates a new component that can be viewed from a menu.
Yes, had a little look at this. I think you’re in for a world of pain if you try structs. Because the structs have to be recursive ( because each tree member has descendants ), which you can’t do.
You can impersonate it with arrays, but then you spend most of your time managing the indexing to recover your data structure.
One easy way is to make a data only blueprint. It just holds variables, one of which is the list ( array ) of the descendants, which are also tree members:
Okay, so I think I know what you’re talking about, I need to create the new children as spawned entities and add them to a list, but how would I get them to appear in a list as structured as the Crusader Kings 2 image I used as a reference? Would I have to use a scroll box within a widget blueprint, and cast to the parent of the children.
Yes, you have to spawn then as if you’re creating something that goes in the world, except they never get seen
After spawn you connect them appropriately to the rest of the tree.
As for the display, that’s a whole other game. Widgets, probably yes, HUD etc. But I’d concentrate on getting the data structure working first… ( you’ll probably have to log a new question about the display ).
Hey, thanks for the offer. I’m going to give it a try and hope it works, I’m not very knowledgeable about structures so I appreciate the offer I’ll post an update when I’ve finished trying.
Ok, cool. But remember, it’s not structures I’m talking about ( I know I used the word up there, sorry ), it’s blueprints, basically. The tree is made out of blueprint actors, because it’s the only way you can have a recursive tree.
Hi, I was wondering if I could pick your brain about how to create it using blueprints as I’ve tried to wrap my head around it but I can’t seem to figure out how to start it as a blueprint.
It spawns the tree member structure in the world ( that’s ok because it has no ‘substance’ ) and set the actor TAG to be the same as the name of the person. We can use this later to quickly find a person. I just made this up as an example, you can do it any way you want…
So, you can see the structure is growing. We can directly find anyone with one BP node GetAllActorsWithTag, but you might want to use some sort of ID if you’re really going for this.
Also I don’t know how heavy this will be if you have thousands of people in the tree. You might want to do an experiement on that.
As far as I know, this is the only way you can get recursive data structures in BP. If large numbers do turn out to drag down performance then maybe you do have to go for just plain arrays. But then you have to cope with representing the recursion with a linear array. Don’t fancy coding that…
No worries. When you want to put the tree in the savegame, you can just make a big array of them all with GetAllActorsOfClass. And when you want to get them back out again, you’ll need to get the array from the savegame and spawn them all…