Lazarus identifier completion not working

windows version 10 20H2
lazarus version 2.0.12
fpc version 3.2.0
cge version 7.0-alpha.snapshot(unstable)

when i try to us the “identifier completion / ctrl+space” in lazarus after creating a new empty project i get this fault.

gamestatetestingstuff.pas(12,52) Error: unit not found: CastleKeysMouse

should the identifier completion work as per normal or am i doing something wrong ?

Looks like Lazarus Code Tools cannot find the CGE unit. Maybe your project doesn’t depend on the necessary CGE packages, so Lazarus doesn’t know they are used?

The project should normally depend on castle_base and castle_window packages, and your Lazarus should be aware of them (you can do this by clicking “Register Lazarus Packages” in the editor preferences, see Installation and building your first application | Manual | Castle Game Engine ; or just install open + compile the packages in Lazarus manually, in packages/castle_xxx.lpk files).

How did you create the new project? And does it compile from Lazarus?

The easiest way to create a project is to use the CGE Editor “New Project” and choose one of the templates. This sets up a project to depend on castle_base and castle_window automatically.


Yes when I first installed CGE I did click “Register Lazarus Packages” in the editor preferences. CGE Editor reported that Lazarus packages had been registered successfully.

When I was unable to use the identifier completion I then tried to install open + compile the packages in Lazarus manually fallowing this video Castle Game Engine tutorial: Installation - YouTube which worked as expected.

I created the new project using the CGE Editor and the templates.

I then double clicked gamestatexxx.pas which launched Lazarus and displays the base code from the empty project template as expected.

It compiles in the CGE Editor via F9 and the window launches displaying the frame rate as expected.

It complies in Lazarus via F9 but the standard empty Lazarus form launches as apposed to the window created by CGE Editor.

I uninstalled and reinstalled both Lazarus and CGE but nothing changed.

Any and all information is appreciate


This means that something is confused. You run a different application than you think from Lazarus :slight_smile: The project that CGE creates does not contain any standard Lazarus (LCL) TForm.

You most likely have the old project (maybe the default, temporary empty LCL project) open. Unfortunately, double-clicking gamestatexxx.pas doesn’t change the project in Lazarus, it just cannot, see Trello – we need Lazarus to expose this feature to use it from CGE.

The solution for now is just that you need to switch to the new project explicitly:

  • from CGE editor choose “Code → Open Project In Code Editor” (and confirm in Lazarus when asked whether to “open as a project”)

  • or, from Lazarus, use Lazarus “Project → Open Project… (F11)” and navigate to CGE project dir, and choose the xxx_standalone.lpi project file.

Do this once, keep the Lazarus open. Now the Lazarus will know the correct project, code-completion will work (as Lazarus knows that project depends on castle_base etc. packages), and running from Lazarus (F9 in Lazarus will work OK (do the same thing as running from CGE editor F9).

yup. double-clicking on gamestatexxx.pas and just expecting everything to magically take care of itself was the issue… my bad :slight_smile:

thank you very much for pointing me in the right direction !

Glad it helped :slight_smile:

To be clear, things should “magically” work in the way you expected. When you double-click on gamestatexxx.pas we should open Lazarus and switch Lazarus project to the proper one. It’s a bug in CGE that we don’t, and we will solve it :slight_smile: In this case we have to ask Lazarus devs first to implement a related feature, and then we can use it.

I did submit a related Lazarus feature request now, Feature request: Ability to open, from command-line, Lazarus file X in project Y (#39338) · Issues · FPC / Lazarus / Lazarus · GitLab .