I have an array from which I select skeletal meshes, and I have extracted those skeletal meshes’ names as strings, and what I’d like to do is when that string contains one of several possible substrings, i want things to happen based on which exact substring was found.
The array has some duplicate meshes with slight variations, which is why I want to select the anim blueprint + one or two more execs based on which base model is being used according to the array, hence the idea to use substrings.
However I ran into a problem, substring checks can only output booleans, and most functions that accept booleans only accept one. I’d rather not create a spaghetti of branches, so what should I do?
This is where i’m at, as an example I have two substring processors up there but like I said, I’m a bit lost on what comes next.
My idea was to set the Model index variable to determine what happens in the multigate based on which substring is detected but I cannot think of any actually nice way to do that (although i can think of one or two really nasty ways)
The ideal solution would be a switch node that could select it’s output based on the substrings directly, however as far as I know switch only supports complete strings.
I absolutely detest it thuogh… I suppose I could use a switch statement using the full string names, it’d be more efficient but a lot more cumbersome to work with… Though if i’m doing that i’d rather just use the integers since i know what they are, less intuitive to read, but less of a pain to maintain…
This looks like you want to map some strings to integer values then search for the appropriate value based on the string within that map.
There’re multiple approaches, the first being assignment of Strings to Integers using a Map, you can create a Map that contains these things up front, assign your array elements to the map and give each of them a value (this isn’t the same as the index value, this is specific to that string).
When you want something from that map you’ll search for the Key that will retrieve the correct Value then pass that off to where ever you need to in the logic chain.
An alternative is to have a Data Table which would contain all the information you need in table form, you could then use the “GetDataTableRow” nodes to retrieve a row of information based on it’s name (which is assigned by you in the data table).
both ways would reduce your spaghetti to a few meatballs.
Is there any good way to assign the array elements to the map or do i have to do it manually for each one?
The map does sound like what i was looking for, but the downside seems to be the same as with a switch (except i suppose it’s got less spaghetti), i’d have to manually input everything and if the array gets new entries i’d have to manually mirror those as well.
Datatables seem like they’re the most efficient way to resolve this all around though. that seems like a really powerful tool, so I’m gonna try that. Thanks!
Is there any good way to assign the array elements to the map or do i have to do it manually for each one?
well it depends on what you’re attempting to accomplish. If you know ahead of time which materials/models/names etc that you’re going to need for your Map/Array/Table then you can create a single entity that you can add to with the easiest workflow.
If you wanted to do this dynamically becuase you wanted to keep it abstract, then you’d be looking to loop over a variable number of possible materials/models that you’d retrieve from some function that you’d have to develop separately.
Since we’re interested in using tables we can explore that one, first we’ll want to create a structure, this’ll be where we can associate types of data with one another:
Now we can use this table anywhere we can access it from and access the information it contains. In the future, when you want to add more variations to the table you can simply hit the add button and include them.
Next you’ll want to make use of 1 or more of 3 nodes:
these nodes allow you to access the names and all the elements along the same DataTableRow that you added earlier. your logic could include iterating through the DataTable at random and choosing a particular set of things for your character to adorn. It could be getting a single element like a material from that row.
If I implement this logic onto a player character that had no skeletal mesh to begin with, it could set both the mesh and the material on that mesh as well as allow me to use it’s name to produce a message:
Here’s my result, Above is the new code using datatables to do everything that needs to be done, commented below is the old code i was using before, it had different sections for different models since they weren’t very cross compatilbe (I’m changing out the mesh ,anim blueprint and setting some morphs based on these conditions)
Just adding a character name option to the structure in the datatable does the trick, i’m using that for that last switch statement you can see at the end of my new code, moving the camera around based on the three possible characters.
This isn’t really code i’m gonna be using in any game, i’m just practicing, pointing out data tables to me was a big help this is kinda revolutionary. The more complicated the code the more useful they seem like they’d get.
The benefit of the new code though is that adding in more characters is a lot simpler, i just add them to the datatable and they’ll automatically be supported by the code if it was done right, theo nly thing i’ll have to manually change in the code are the camera adjustments.