# TUIState is now TCastleView, methods to change the view are now part of Container, new slick UI when opening the project

**URL:** https://forum.castle-engine.io/t/tuistate-is-now-tcastleview-methods-to-change-the-view-are-now-part-of-container-new-slick-ui-when-opening-the-project/703
**Category:** News
**Created:** [December 28, 2022, 6:51am UTC](https://forum.castle-engine.io/t/tuistate-is-now-tcastleview-methods-to-change-the-view-are-now-part-of-container-new-slick-ui-when-opening-the-project/703 "2022-12-28T06:51:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [December 28, 2022, 6:51am UTC](https://forum.castle-engine.io/t/tuistate-is-now-tcastleview-methods-to-change-the-view-are-now-part-of-container-new-slick-ui-when-opening-the-project/703/1 "2022-12-28T06:51:01Z")

</div>

| [![Platformer game view](https://forum.castle-engine.io/uploads/default/original/2X/0/01e421c7a3a8c916b08dcb78c1deedfad470cb76.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/12/platformer_map.png?ssl=1 "Platformer game view") |
| [![Editor UI to open existing views](https://forum.castle-engine.io/uploads/default/original/2X/e/ea8b72f5c9af9e830f3c70effb2cf7a715e0c4b2.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/12/views_in_editor.png?ssl=1 "Editor UI to open existing views") |

We have an important change to one of our most important concepts: _states_ (`TUIState` descendants) are now called _views_ (and descend from `TCastleView`).

It’s a change in terminology, and a change in API. While previously you were changing states using class functions and properties, like `TUIState.Current := Xxx`, now you should use regular container methods, like `Container.View := Xxx`.

Oh, and to this we add a new slick UI when opening the project 🙂

## Why?

It addresses two things:

1. The name _“state”_ was too generic and thus meaningless. Almost every variable and object instance in your application can be called some “state”.

It made sense if you think _“user interface state”_ or _“state of a [state machine](https://en.wikipedia.org/wiki/Finite-state_machine)“_… but the sole word “state” is too generic.

Moreover, `TUIState` class name is not consistent with CGE naming. And `TCastleUIState` or `TCastleUiState` are too convoluted. So for a long time I knew it will have to be renamed to `TCastleState` or `TCastleView`. I finally finished the work to go with `TCastleView`.

_“View”_ doesn’t seem too bad name. It clearly communicates it’s something visual and is a way to “see” CGE stuff. And, _view_ isn’t that often used as a noun, so when someone says _“This view is amazing”_ you can fairly safely assume they talk about `TCastleView` (assuming you’re in the middle of CGE manual, not on a hiking trip 🙂 ).

It is consistent e.g. with [React view](https://reactnative.dev/docs/view).

2. The way we changed states, using `TUIState` class methods/properties, could be improved to use simple methods on `Container`.

## Upgrading

This change is _100% backward-compatible_. The old code will continue to work, though we advise you to upgrade to new names and container methods/properties.

In total, the upgrade path in typical applications is rather straightforward, although it will require to do a lot of replacements (I recommend to commit everything to your version control before doing the upgrade, and then have a nice diff to audit with state-\>view upgrade):

1. Rename `TUIState` -\> `TCastleView`.

2. Remove `CastleUIState` unit from your uses clause. Make sure unit `CastleUIControls` is there (it likely is there already).

3. Change in ApplicationInitialize:

4. Change in various states (views):

5. Optionally, as a final touch: rename your units and designs.

## New editor UI when opening new project

This is accompanied by a cool upgrade to our CGE editor UI. It happened because of independent reasons (I did UX testing on a live human at Christmas :), and came back with lots of nice conclusions) but it is nicely connected with the whole _views_ terminology.

Now, when opening any project, you will be greeted with a UI to

- compile and run / stop the project
- create a new view (Pascal unit and design)
- open an existing view

This UI emphasizes your most recommended actions after opening the project.

## Docs

Our documentation, including important chapters about [view events](https://castle-engine.io/view_events) and [managing views](https://castle-engine.io/views), has been upgraded to new terminology.

Our examples are also fully upgraded now to use _view_ terminology everywhere.

---

<div class="post-metadata">

### Author: ![Carring](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/carring/32/1950_2.png) [@Carring](https://forum.castle-engine.io/u/Carring)
#### Post date: [January 23, 2023, 6:56am UTC](https://forum.castle-engine.io/t/tuistate-is-now-tcastleview-methods-to-change-the-view-are-now-part-of-container-new-slick-ui-when-opening-the-project/703/2 "2023-01-23T06:56:18Z")

</div>

I have followed the upgrading changes but get this error?

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/3/3bdf6b4817fc637ec85225a812236af2d7fb193d.png)

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [January 23, 2023, 11:54am UTC](https://forum.castle-engine.io/t/tuistate-is-now-tcastleview-methods-to-change-the-view-are-now-part-of-container-new-slick-ui-when-opening-the-project/703/3 "2023-01-23T11:54:11Z")

</div>

Look at the type of your `StatePlay` variable (it is in `GameStatePlay` unit, you can just ctrl + click on it in Lazarus to jump to declaration). It likely has a type `TStatePlay`, so here you should create `StatePlay := TStatePlay.Create...` .

Also, `TCastleView` is in `CastleUIControls` . Which you can find by searching for it in API docs, [Castle Game Engine: CastleUIControls: Class TCastleView](https://castle-engine.io/apidoc/html/CastleUIControls.TCastleView.html) . But, you don’t want to create just `TCastleView` there.

---

<div class="post-metadata">

### Author: ![Carring](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/carring/32/1950_2.png) [@Carring](https://forum.castle-engine.io/u/Carring)
#### Post date: [January 23, 2023, 12:37pm UTC](https://forum.castle-engine.io/t/tuistate-is-now-tcastleview-methods-to-change-the-view-are-now-part-of-container-new-slick-ui-when-opening-the-project/703/4 "2023-01-23T12:37:29Z")

</div>

I now have StatePlay := TCastleViewPlay.Create(Application) in TStateMenu but now I get an error message I did not have before when using TStatePlay?

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/5/501a72e1fcbee655a15e1ec1b0d5dbda85391026.png)

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/c/c13b5065745fea77619300542a24b77b84b46ae4.jpeg)

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [January 23, 2023, 2:44pm UTC](https://forum.castle-engine.io/t/tuistate-is-now-tcastleview-methods-to-change-the-view-are-now-part-of-container-new-slick-ui-when-opening-the-project/703/5 "2023-01-23T14:44:33Z")

</div>

Hm, this error message seems unrelated to TUIState → TCastleView rename, and indicates some problem you had before or that you did something weird at conversion. I’m afraid I cannot tell where’s the problem looking at the screenshot.

Please submit a testcase to reproduce the problem, preferably a small testcase.

If you have a version control (as I recommended in [TUIState is now TCastleView, methods to change the view are now part of Container, new slick UI when opening the project – Castle Game Engine](https://castle-engine.io/wp/2022/12/28/tuistate-is-now-tcastleview-methods-to-change-the-view-are-now-part-of-container-new-slick-ui-when-opening-the-project/) as I recommend in general – use version control) then please look at your changes, and see whether they make sense, if you didn’t touch anything unusual.
