# Replacing Uscript States with c++?

**URL:** <https://forums.unrealengine.com/t/replacing-uscript-states-with-c/20944>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [February 12, 2015, 11:15pm UTC](https://forums.unrealengine.com/t/replacing-uscript-states-with-c/20944 "2015-02-12T23:15:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neongho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neongho](https://forums.unrealengine.com/u/Neongho)\
**Post date:** [February 12, 2015, 11:15pm UTC](https://forums.unrealengine.com/t/replacing-uscript-states-with-c/20944/1 "2015-02-12T23:15:25Z")

</div>

I think that states were truly an awsome feature for gameplay coding in unrealscript.

Is there any way to create some kind of structure in c++ replacing the states of unrealscript ? What would i use ?

---

<div class="post-metadata">

**Author:** ![Emidee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Emidee](https://forums.unrealengine.com/u/Emidee)\
**Post date:** [February 13, 2015, 2:09pm UTC](https://forums.unrealengine.com/t/replacing-uscript-states-with-c/20944/2 "2015-02-13T14:09:12Z")

</div>

You can have a look at UT source code. If I remember correctly, they have C++ states for their weapon.

You can also have a look here : [State · Design Patterns Revisited · Game Programming Patterns](http://gameprogrammingpatterns.com/state.html)

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [February 13, 2015, 4:41pm UTC](https://forums.unrealengine.com/t/replacing-uscript-states-with-c/20944/3 "2015-02-13T16:41:36Z")

</div>

They’re just Enums. You can use them for anything.

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![Neongho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neongho](https://forums.unrealengine.com/u/Neongho)\
**Post date:** [February 13, 2015, 6:59pm UTC](https://forums.unrealengine.com/t/replacing-uscript-states-with-c/20944/4 "2015-02-13T18:59:36Z")

</div>

Thanks for all the information, i don’t want to write a chaotic boolean machine try code, Going for the enums for that.

---

<div class="post-metadata">

**Author:** ![ArcainOne](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ArcainOne](https://forums.unrealengine.com/u/ArcainOne)\
**Post date:** [February 17, 2015, 9:42pm UTC](https://forums.unrealengine.com/t/replacing-uscript-states-with-c/20944/5 "2015-02-17T21:42:03Z")

</div>

There exist a design pattern that you can implement for this (and even blueprint it)

> **[State pattern](https://en.wikipedia.org/wiki/State_pattern)**
>
> The state pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes. This pattern is close to the concept of finite-state machines. The state pattern can be interpreted as a strategy pattern, which is able to switch a strategy through invocations of methods defined in the pattern's interface.
> The state pattern is used in computer programming to encapsulate varying behavior for the same object, based on its internal state. This can...

Basically You can create State class derived from a UObject, AActor or even make it a structure. Then create subclasses of the state class when you need them. Granted if your Pawn has 3 movement states then you’ll have to create 3 different C++ classes… or if you JUST implement the state in Blueprints then suddenly you are working similar to how UE3 states worked anyway.
