Code Completion XCode

How do I enable code completion for a C++ project in Xcode?

If you have it enabled in Xcode preferences (Text Editing tab), it should kick in automatically once Xcode finishes indexing the project, which may take a lot of time (I mean like an hour or so, when it’s doing it for a first time). If it doesn’t work for you, let me know.

Hi Michael,

I have it enabled in the Xcode prefs, and I’ve tried all of the usual tricks, deleting the derived data etc, but still, no code completion!

The source code files are added to the command line target, but if I try and build that I get an error complaining about the engine.h.

Here’s a little explanation on how UE4 Xcode projects work.

As you might’ve noticed, we don’t use Xcode to compile/link the engine, but rather External Build Tool targets that build the engine using our UnrealBuildTool. The downside is that at the moment Xcode is not able to fully compile many of our source code files during indexing, as it ignores important build settings for External Build Tool targets, like preprocessor definitions or header search paths. It even dons’t care about source code files being added to the target.

That’s where UE4XcodeHelper target comes in. I added it so that we can give Xcode at least basic info about our code. Not enough to fully compile the source code during indexing, as I mentioned, but enough to know which file to index in a first place and where to find most of headers. For me it’s been working quite well, but I have to confess that mostly tested it with a full engine code. Maybe something is currently broken in projects stored outside of UE4 source code tree :confused: You’re the first one reporting this, so let me do some tests Monday.

One question, though. Are you able to successfully build your game target despite this Engine.h error? If yes, that means that the problem is limited to Xcode’s indexing. If not, that’s another story and I will need more details.

Hello,

In normal UE4 Xcode project without source code it is not possible to go to engine definitions so it is very difficult to develop than. Full Source is the only one alternative.

I tried to build Editor with Xcode. Debug builds even while indexing…shipping not.
Indexing would be fine if it would not happen for every new UE4 project :frowning:

Shipping build does not compile even after indexing.

UnrealEngine/Engine/Source/Editor/LevelEditor/Private/SLevelViewport.cpp
UnrealEngine/Engine/Source/Editor/LevelEditor/Private/SLevelViewport.cpp:2891:69: error: no member named ‘GetExecBind’ in ‘UPlayerInput’

Yes I can build my project, either via Xcode by building the editor target, or in the editor itself using the compile button.

I can’t however build the helper target as explained above, and the project refuses to index (probably because the helper won’t build).

Hope that helps.

Sorry for confusion. The helper target is not something you need to build. It’s just there to help Xcode index the project. As I mentioned earlier, I’ll check the code completion in a project without full source code Monday. This is a different matter than the following:

I’ve spent quite a bit of time tweaking our Xcode project generator so that the helper target at least partially compiles, enough for the code completion and syntax highlighting to mostly work (at least where I tested…), but is needs more. Having the helper fully compilable is one of the top things on our Mac todo list.

That’s another confusing thing, I’m afraid :frowning: Shipping configuration is for games only. We should’ve added a proper error for trying to build the editor in this configuration… For the editor you should use either Debug or Development (which is equivalent of Release from some other projects).

Okay, thank you for information.

Thanks Michael, all your help is greatly appreciated, really loving UE4!

there is macro to unavailable GetExecBind, but I don’t know why,

#if !UE_BUILD_SHIPPING   // comment out for temp fix problem

	bool Exec(UWorld* UInWorld, const TCHAR* Cmd,FOutputDevice& Ar);

	/** @todo document */
	FString GetBind(FKey Key);


	FKeyBind GetExecBind(FString const& ExecCommand);

	/** Execute input commands. */
	void ExecInputCommands( UWorld* InWorld, const TCHAR* Cmd,class FOutputDevice& Ar);
#endif

Glad I could help. If you have any more problems or questions, just let us know.

I don’t recall what exactly is disabled in Shipping, or why these particular functions are, but the general idea behind it is that Shipping does not include stuff that’s needed for games only during development, for maximum performance and minimum exe size, etc. This includes parts of the engine that are only used by the editor and tools, which results in editor not being compilable in Shipping config.

Hi Michael, I have the same problems with autocompletion (doesn’t work).

I already started working on improvements in this area, will let you know when I have any news, hopefully early next week.

Is there some kind of workaround meanwhile an official patch is released ?

Meanwhile Mike is working in a solution to code autocomplete, this is how you could integrate your game module within engine source code.

  1. Download [source code release pack][1] and follow the instructions.
  2. Execute GenerateProjectFiles and check there is no error.
  3. Place your game folder at root level structure together to \Engine, \Samples, \Templates
  4. Create “GameProjects.uprojectdirs”, write ‘.’ inside and save.
  5. Execute GenerateProjectFiles .uproject -game
  6. Execute GenerateProjectFiles to generate the new UE4.xcodeproj with the complete structure
  7. Open UE4 project with Xcode

Reference:

It is does not give you autocomplete.

Hello everyone.

I don’t have autocompletion in project with full source code. Can somebody explain, what I’m doing wrong?

Here’s what i did:

  1. Forked engine at github, cloned it, downloaded required dependencies (excluding optional), generated project files.

  2. Opened project with xcode, waited for indexing, then built editor with “UE4Editor - Mac” target.

  3. Created new project (blank, without example assets) in custom directory (neither engine root, nor “Documents” folder).

  4. Created new class, derived from AActor (via “Add code to project”).

  5. Opened my project in xcode, waited for another indexing. Still no autocompletion and jump to definition (even on my new class and it’s own fields). “Jump to definition” on AActor shows “Symbol not found” message. Same with “UE4XcodeHelper” target selected.

  6. Built project with “MyProjectNameEditor - Mac” target. It took some time (whole engine was rebuilt I think). Then relaunched xcode. Still looks sad.

Code completion feature in prefs, of course, is enabled.

Thanks, and sorry for my poor english.