Download

Is there a way to set component/blueprint prefix name to something fixed when the game starts?

This is kind of hard to explain but I try.

I have a trace that captures the name of the object it hits and sets it as a String variable.
Another action then happens based on what is written in that string variable.
It works just as I want.

Except, the trace reads the actor names in way of “ExampleActor_Blueprint_C_1.ExampleObject”.
I only need the “ExampleObject” part of that to make it work. So, I use a string replace node, that takes
the beginning of the string away, and everything works perfectly again.

Except that at the part of “C_1”, the number changes from a game restart to restart. Sometimes it is C_0, sometimes C_2.
The string replace node is picky and wont take that prefix away unless its just the way written in it.

  • -mark in the spot of the number doesnt do the trick either. Note that there actually is only 1 of those blueprints and actors ever
    used. Name would never collide with something else in my game even if I set it fixed.

Thanks for any help.

It’s not really a good idea to rely on the name of an object. What are you using it for?

But, you could use Rama’s plugin which contains an explode string node. You input a string, choose a separator character, and it makes an array of the result.
So if you have ExampleActor_Blueprint_C_1.ExampleObject and split it using _ as the separator you get:

0: ExampleActor
1: Blueprint
2: C
3: 1
4: ExampleObject

In the array it returns, then you just get index 4. (The words will change but the format won’t)

I have a collision capsule attached to each bone of my skeletal mesh, and those collision boxes are named the same as the sockets they are child of.
So when my trace hits a collision capsule, it takes it as the name and saves it as a variable, which then can be directly used later for spawning child actors/applying damage/other things to the socket chosen.
It would be doable with on hit events etc, but using 1 variable was a shortcut I came up with which helps me to use just 1 event instead of many many many collision events.
Probably there could be other ways to do it too but I am no programming wizard so I was happy with what I found to be working.

The example you gave does sound like a working solution though! I have been little scared to download third party nodes though, in worrying of them being out of date/not compatible with latest
engine versions. I am using 4.9 now, but if it is safe I could give those a try.

EDIT:

Well doooh. As always, asking something after getting stuck means that I find a fix myself right after. I was using wrong node type to get the name of the object. Changing it stopped making the prefixes.
Maybe its when you write something down and look at your problem through text, you start to see the problems and find the solutions… I probably should start just writing to notepad whenever I have a problem instead of asking here :P. But perhaps someone might learn from my mistakes this way at least hah. And thanks for the suggestion!

You could possibly use component tags for that.
In your collison shapes details scroll down and find tags, and add a tag here with whatever you want.
Then, on your trace, with the break hit result, drag from Hit Component, and type Component Tags, this returns an array of the components tags, if you only have one, then use get 0, and you have your tag. It’s a name type, but you can convert it to string if you like

Rama’s blueprint nodes are very popular and useful, and he updates for every release, so that would be fine too. I include his nodes in nearly every project I start

actually, now that I think about it, I think he also has a node that returns the name of the closest bone on a hit character.

Ah true! Thanks for the info! Seems that there is a get Tag node as you said, which could be used just the same way via string variable as I am using. Then I would need to have the tags named the same as the parent bone is, instead of the component itself. Works the same.
Is there a particular reason by the way, why Get Object Name shouldnt be taken and used, now that I am using the correct node that is not making the prefixes in the string?

Only since it’s a variable you don’t have complete control over, so you can’t be sure what it will be, which could lead to unexpected results. It also changes in PIE, versus the actual game. It can be useful too, but often there is a cleaner way of doing the same thing, in my opinion.