Get a number from Display Name
So lets say Im spawning boxes, and so their display names are as I spawn them: "Box", "Box_1" "Box_2" ... "Box_999"
Is there any way to extract an integer that would be the number of the box?
In other words: Can you convert a string "Box_9" to an integer "9"?
You can use two methods, a split or a parse. A split works fine when you know for a fact it never changes from "ClassName_#". I recommend a parse, as it will work on everything from "ClassName_#" to "ClassName_Child_Instance-test_#". You get 0 for "ClassName". Works without fail. Enjoy.
answered Jan 03 '19 at 07:20 PM
There doesn't appear to be a built-in way to do this via Blueprint, but it is definitely doable using C++. Check out this page on the UE4 Wiki and also the FString documentation page from the official docs to learn more.
Bottom line, you should be able to write up some simple wrapper functions using the above references, that you can then expose to Blueprint for you to use anywhere in your project.
answered Jan 02 '19 at 06:40 PM
Just set an Int variable called Index in the box BP and set it once spawned. Then just get the index.
answered Jan 03 '19 at 06:21 PM
FName::GetNumber() might be what you're looking for.
answered Jan 03 '19 at 05:51 PM
If you know the position of the number, you can use the Get Substring node, and convert the output to an integer.
Hope this helps!
answered Jan 03 '19 at 06:10 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here