Creating a Text Based Adventure using Blueprint?

So, I have a vision of a text based game scripted using blueprint. Basically, the lower half of the screen would be a sort of command prompt, allowing input and displaying the output, while the upper half of the screen would display the graphics which would be controlled by inputted text. My question is this; how would you go about creating the interactive dialog box, and what commands would you use for getting the input, and displaying the output? Thanks!!

Anyone? I’d really like to try to get this project going.

Let me try some things and i’ll let you know if i can help you.

Not that I can help, but great idea! :slight_smile:

I’d appreciate that, thanks!!

I’ve got good news and bad news. Good news is that i figured out how to get all the keyboard input in blueprints, bad news (might be) that it required some c++.

I’m not sure if you’ve got everything to compile the code with, if not i’ll try and see if i can figure out how to make it a plugin.

As for the visual part, you can do most (not capturing the input but i’ve got that covered) in a blueprint based on a HUD class.

Wow, thanks for the quick help! I don’t mind a little C++. I’m working on a mac and can compile in xcode. I’m actually studying C++ at the moment so having to use it may be beneficial to me. Can’t wait to hear what you found out :slight_smile:

That’s great since i couldn’t really figure out plugins yet (maybe if i take a little bit more time).

Below is the relevant code i used. After this you need to set your viewport to the custom class (in the editor Edit->Project Settings->General Settings->Game Viewport Client Class).
Create a blueprint based on the custom playercontroller, and then you can implement InputChar.
Hope this helps.
If you need help with the HUD part because you’re still not sure how to do it, i’d be happy to help.


#pragma once

#include "GameFramework/PlayerController.h"
#include "TextBasedPlayerController.generated.h"

class ATextBasedPlayerController : public APlayerController

	UFUNCTION(BlueprintImplementableEvent, BlueprintCosmetic)
	virtual bool InputChar(int32 ControllerId, const FString& Unicode);


#pragma once

#include "Engine/GameViewportClient.h"
#include "TestViewportClient.generated.h"

class UTestViewportClient : public UGameViewportClient

	virtual bool InputChar(FViewport* Viewport, int32 ControllerId, TCHAR Character) OVERRIDE;


#include "TextBased.h"
#include "TestViewportClient.h"
#include "TextBasedPlayerController.h"

UTestViewportClient::UTestViewportClient(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)


bool UTestViewportClient::InputChar(FViewport* InViewport, int32 ControllerId, TCHAR Character)
	// should probably just add a ctor to FString that takes a TCHAR
	FString CharacterString;
	CharacterString += Character;

	bool bResult = false; 

	ULocalPlayer* const TargetPlayer = GEngine->GetLocalPlayerFromControllerId(this, ControllerId);

	if (TargetPlayer && TargetPlayer->PlayerController && TargetPlayer->PlayerController->IsA(ATextBasedPlayerController::StaticClass()) )
		bResult = Cast<ATextBasedPlayerController>(TargetPlayer->PlayerController)->InputChar(ControllerId, CharacterString);

	if (!bResult)
		Super::InputChar(Viewport, ControllerId, Character);

	return bResult;

Thanks for supplying the code. I’ll see what I can figure out. I’m an animator mostly, and have messed around with UDK and Unity in the past, but UE4, and coding in general are new to me. I will definitely need help setting up the HUD when you get some time, if you don’t mind. And as far as what you supplied, I’ll mess around and see if I can figure it out.

EDIT: Ok so here’s where I’m at. I created those three files via File->Add Code to Project. I can’t figure out though, how to get them to show up for me to select. In the preferences, the new viewport class does not show up, as it is not in the content browser. I can’t manually add it to the content browser because it doesn’t allow selection of .cpp and .h files.

You should have 4 files, also the TextBasedPlayerController.cpp (if you did everything correct, but i didn’t post it because it’s still empty).

Since GameViewPort is not based on Actor you can’t use it in the content browser, you really need to go to (in the editor Edit->Project Settings->General Settings->Game Viewport Client Class).

Make sure you recompiled your code, you can check if it’s working by trying to make a blueprint based on TextBasedPlayerController.
Also, because my project’s name was TextBased, it included TextBased.h in TestViewportClient.cpp, you should replace TextBased with your own projects name.

I do have all four files. When I open the project in xcode, however, and try to build it, I get some errors that prevent it from building. I’m not very familiar with compiling and coding, like I said, I’m more of a visual guy, so I could be doing something wrong. I’m assuming I need to compile within xcode and then it should show up back in UE?

The problem does seem to be in the compiling. Here’s what I am doing:

  • File -> Add Code to Project
  • I then created the required code
  • From there, I opened the newly created xcode project, and closed UE4
  • In xcode, I hit build, and came back with a few errors preventing me from building it. (One of which says I need an iOS Developer license, I’m just using a free developer’s license to use xcode, that shouldn’t be an issue…)
    -Trying to open UE4 again results in errors saying there is uncompiled code and I cannot open the file because it is missing modules

Yes that should happen, could you post the errors, then i might be able to help.

Well, this is what I’m getting

Code Sign error: No matching codesigning identity found: No codesigning identities (i.e. certificate and private key pairs) matching “iPhone Developer” were found.
CodeSign error: code signing is required for product type ‘Application’ in SDK ‘iOS 7.1’

The only other ones are automatic fixes and little things like adding a placeholder for iOS icons. The two above are what is preventing it from building it looks like. However, I shouldn’t need a paid developer license to just compile code for UE4. That would only be needed to build and submit to the App store I believe.

I feel like it’s trying to do something it shouldn’t…all I want is for the new cpp files to be compiled, not compile a whole project for iOS and OSX, which I believe is part of what it’s trying to do.

I did some searching on google, and i don’t think it’s related to UE4–error-details-codesign-error-code-signing-is-required-for-product-type-application-in-sdk-ios-70

and just to be sure, did you follow this when setting up xcode?

Thanks for the resources. It looks like it is a problem with my developer certificates. It is telling me I need a paid iOS Dev account, which shouldn’t be the case. I’ll have to look into it more. It’s a bummer, I was really hoping to get going on this game.

In the meantime, while I try to get the compiler working correctly, if you feel like messing around with it, a plugin would be wonderful. And maybe a little more in depth information on how to get the HUD class set up to display the in/out text and the graphics window on top of that. I’d be willing to throw you a few bucks in exchange for helping me get to a point where I can essentially have a template for this “style” of game I’m trying to make.

I’m working on it (not the plugin) right now, though i’m not really sure how its going to work out :slight_smile:

i’ll probably have more time tomorrow, so then i’ll probably start mastering plugins.

Also, do you (or anyone esle) know if i gave my project to you it would still work?

You should check out the HUD example in the content examples, and also the info box in the office blueprint example. It’s a little bit involved getting the text nicely formatted on the screen – you might want to hold off a few months until the UI stuff is hooked into blueprints.

The bigger problem you’re going to face: there’s a lack of string processing nodes in Blueprints. You’ll have to build your parser in C++. There’s many examples of text adventure style command parsers on the web. You can just type “interactive fiction parser” or “text adventure parser tutorial” into Google. You might also want to look at Inform7 is hands down the best IF parser on the planet, and it runs on a virtual machine called a z-machine. Most text adventures (including the original Zork) run on a z-machine.

It would be very tricky, but if you could get the z-machine running within UE4, you could then build the text adventure stuff with Inform or another z-machine content creation tool. With Inform 7 in particular, the resulting compiled z-code would come with a ready-made parser/base game world that’s sophisticated and time-tested. You could then add, into your z-code game, special tags that your own C++ program could parse out and send as events to UE4.

For example, when an object is picked up, the z-code might send out a formatted tag like [object 1123 TAKEN].

There’s extant code for z-machines you can look at. For example: Again, tricky, but in theory it should be possible to integrate it with UE4.

Probably you’re just looking to build your own simple parser, but even then, I suggest you look at Inform to get an idea of how parsers tend to work. Either way, good luck and have fun!

EDIT: I just looked, and it turns out I was slightly wrong about the text processing nodes in Blueprints. With the “Parse Into Array” node, it’s actually plausible to build a text parser in Blueprints. Though it would still require a lot of elbow grease. I’ll leave the above mess as is as a monument to my hubris!

Thanks for the info. I’ve looked into inform a while back but wrote it off thinking that it wouldn’t be of use since I knew I wanted to create this game in Unreal, mostly so that I can incorporate a graphical element to it. As you can tell, I’m NOT a programmer, however I am interested in learning the basics of it whilst planning out this project. My goal is to eventually have a template, much like the default FPS, TPS, Top Down, etc that come with the Engine, however mine would be a Graphical Text Based template.

For anyone wondering, this is an rough image of the type of template/game I’m attempting to create. Of course, the final game will be much more shiny and polished, the template will remain the same. Input/Output text box on the lower third of the screen, with a larger area up top for displaying the graphics.


First of all, did you get my PM?

Second, you might want to keep an eye on this, i think it might be of use for you.