Player name in dialouge

So I would like the player to be able to name themselves so if there name is Bob the NPC’s can say,
“Hello Bob”
I can think of a way to do this and that would be to have a format text where the name is inputted. Now because I have a possible solution I just want to make sure there isn’t an easier way, For example in RPG Maker in a text box you can put “/n” in the text and it will automatically put the players name with no extra coding or anything. I am just curious if UE4 has a similer function.

So your player character could have a variable that is something like MyName of, say, type String. Could have a widget pop up at some point in your game, lobby maybe???, which would set MyName in the player character.

I think you are saying you want a random NPC to say “Hello Bob” as they pass by the player character. If so, you could have a collision box around the NPC of which when a collision of the type of player character is encountered, you could get all overlapping actors of class player character and read their MyName variables and display them above the NPC.

Thoughts?

That’s more or less what I was planning to do, I was just hoping there was some secret feature of UE4 that would allow for the name to just be pulled.

so random npc with a collison box and all that but all they have is a widget with text that says “Hello /playername” and the engine would replace it /playername with the well the players chosen name.

If you find the secret feature that does this, please post. I would be interested in utilizing this…

So after some searching around what i wanted which included trying to co-opt the localization feature inside of unreal i figured out how to do it.

Useing the “Replace string Node” you can replace words in any given text. for example…
In the text variable it would say something like
“Hello /n, how are you doing?”

in your widget it would look like this

"Hello Bob, how are you doing?

the part circled in red is the important part. Using this you can attach this to any dialouge or notification and include a special word for your custom players name. you put the custom word such as /n into from, then you can grab the variable that holds the player name from wherever it is and plug that into the to.

Its not the quick secret trick i wanted but its far better then trying to use format texts and clever bools to make it work.

You can use format text here, instead of “/n” use “{PlayerName}” in the dialogue and you can add a PlayerName pin to the Format Text node :

Format Text Details Panel :
image

2 Likes

Just to mention it in addition to @Extrone:

You can use the formated function even with StringTables. This is useful for Localization of your Game via Unreals Localization tools. Just add the

{parameterName}

into your StringTable Inputs. When you set this Localized Flag in your FormatText, the parameterName Input will appear, too.

3 Likes

Oh that is much easier thank you I appreciate it, I didn’t relize format text would work that way.

1 Like