I’ve been learning visual scripting for a while (as I literally don’t know C++) working on my solo project and I’ve come to a point where I’m just stuck because of blueprint performance.
I’m working on a text based NPC dialog system where NPC can understand sentences from a Widget TextBox and answer the player. I added NPC personnality system that modifies the way NPC will answer the player (based on 5 variables: Openness, Conscentiousness, Extraversion, Agreeableness and Neuroticism). Everything works so far, I’ve succeed in having simple conversations with different NPC personnality, BUT:
When it comes to process player words, sentence and search for an answer (after pressing Enter when TextBox is being selected), it can takes sometime (depending on the sentence) about 1min where the editor just freezes before successfuly give an answer.
I assume you have to know how I managed to do that, so I’m gonna explain what I did and if you guys have any idea of what might slow the whole process, that would be just awesome… cause I’m stuck for real on that one…
To sum up, I worked with lots of string arrays containing lots of different words that I categorised by types: I, Me, My, Mine… is in an String Array called PlayerRef while You, Your… is called NPCRef etc. All of them are packed in a final single string array containing every words that can be understood. These words are compared to the sentence typed by the player and if it contains a word that is in the general string array, then this particular word is added to another string array called “Sentence” through a “ForEachLoop”. So at the end all the words contained in that “Sentence array” is what the player said, word by word.
This Sentence Array goes for another loop where there is a fonction linked to the loop body called “Understand Sentence” that searches in what specific array each word is: (Player Ref, Character Ref, Location, State, Desire…). Just a sequence of “Array Contains?” linked to a branch, if “True” then append the word to another String Array called WordsUnderstood. Why do I do that? Well because the player can type different words that means the same, so by this process I append all words of the word category: Exemple: “I like apples”, “like” can be replace by love, or appreciate…)
That leaves us with an string array containing all words contained in thetxbox player sentence WITH its synonyms. When the understanding Each loop, is complet it goes to a final fonction that is “SearchForAnswer”, this final one is the longest, it’s a sequence of all possibles sentences that can be answered by the NPC. A branch with : If WordsUnderstood Array contains “word1” and “word2” and “word3”… Or “word1” and “word2” and “isQuestion” then set meaning (String Variable where you can just type in what is the meaning of the sentence) and add it to a “meaning” string Array (thats a lot of arrays that’s maybe why it is slow). Finally (I’ll jump this part), it gets through a final fonction that defines NPC personnality and answer if Meaning array contains what play said.