Newsletters

The CV2 State Machine

Creators are making incredibly impressive rooms these days. Many of these rooms involve managing lots of data and intricate circuitry, performing remarkably complex tasks. Recently, we talked about how Data Tables can help on the data side. 

Now we’re introducing The State Machine to help on the circuits side - it manages all that awesome complex circuitry easily by breaking things down into simpler states.

Fast Facts

  • Simplified Complex Functionality: State Machine chips simplify the management of intricate circuitry in Rooms by breaking it down into simpler states.

  • One State at a Time: These chips ensure that only one child state is active at a time, reducing the risk of conflicts between different behaviors and eliminating the need for complicated condition checks across different states.

  • Modular Design: Easily add, modify, or remove states within the State Machine, just like you would with a circuit board.

  • Nested State Machines: State Machines can also be nested within State chips, allowing for more intricate control over sub-states.

  • Synced or Unsynced: State Machines can be configured as synced or unsynced. Synced states provide consistency across players in multi-player environments.


THE STATE MACHINE CHIPS

You can now add a CV2 State Machine chip to your rooms from the palette to get started. Think of the State Machine chip as a circuit board with a superpower: only one child state is active at a time. That means the events inside a State Machine execute when a state chip is active (and do not execute when that chip is inactive). 

 
 

What would a State Machine be without its states? Enter the State chip. If you’re familiar with circuit boards you know that you can edit into them to add more chips. The same is true for the State Machine chip. 

The State chip partners with the State Machine chip. By default, a State Machine chip contains a child State chip. Remember, only one child state is active at any given moment.

 
 

Let’s go deeper into the chip hierarchy by editing into that State chip to see what makes it tick. State chips come with child chips that allow you to go to other states and control what happens when entering or exiting this state.


NPC STATE MACHINE EXAMPLE

Now that you have a rundown of what the State Machine chips are, let’s see them in action!

In games, Non-Playable Characters (or NPCs for short) often use state machines to handle the complex functionality needed to bring these characters to life. Using State chips, we can easily transition to a specific NPC state, regardless of whatever state it happened to be in before.

Let’s create a simple NPC state machine example to see how the pieces come together. Say we want an enemy NPC with three behaviors: patrol, take cover, and attack. 

  • Drop a State Machine chip into the room from the palette and use the configuration menu to name it “NPC State Machine”.

  • Open up the palette and add in two event definition chips that control the NPC’s behavior: “NPC Got Shot At” and “NPC Sees The Player”.

Edit into the State Machine chip. 

  • Since State Machine chips come with a child State chip by default, let’s rename this default chip to “Patrol State”. 

  • We will also add two more state chips from the palette and rename them “Take Cover State” and “Attack State”.

We want the NPC to patrol by default, so the “Patrol State” state needs to be active. Since we renamed the default State chip that came with the State Machine, we’re all set.

If we ever want to change the default active state, we can do that by configuring the NPC State Machine chip and changing the default state value.

Let’s imagine that our NPC takes out high-tech range-finding binoculars when they start patrolling and puts them away when they stop patrolling. Plus we only want them using binoculars when patrolling. Keep this in mind, we’ll use the binoculars to show how a state machine can help simplify complex functionality later.

  • Edit into the “Patrol State” chip to set up what happens when the NPC enters and exits this state. 

  • Use the State Did Enter event receiver that’s already in the State chip to execute the circuits needed when “Patrol State" becomes active. In this case, we’ll connect it to a circuit board that tells the NPC to take out its binoculars and start patrolling. 

Similarly, use the State Will Exit event receiver that’s already in the State chip to put the NPC’s binoculars away and stop patrolling whenever this state becomes inactive.

Now let’s tell the NPC what happens when it gets shot at (take cover) or if it sees a player (attack). We make these transitions happen with our State Constant and Go To State chips.

  • Add two event receivers and configure them to use the event definitions we created earlier: “NPC Got Shot At” and “NPC Sees The Player”.

  • We want to create transitions to two other states: “Take Cover State” and “Attack State”. Our State chip comes with one State Constant so we only need to add one more. Configure one of them to “Take Cover State” and the other to “Attack State”.

  • Connect one of the State Constants to the Go To State chip that’s already here in our State chip. Add one more Go To State chip from the palette and connect it to the other State Constant. 

  • Finally connect our “NPC Got Shot At” and “NPC Sees The Player” event receivers to the Go To State chips. Now when the NPC gets shot at, it will go to the take cover state. When the NPC sees the player it will transition to the attack state.

There you have it! We’ve created an NPC that has three separate states that will never conflict with each other because only one child state is active at a time! 

Thanks to this, we don’t need to worry about whether another NPC Got Shot At event receiver inside a different State chip does something that conflicts with our patrol behavior. Event receivers inside inactive State chips don’t execute. No need for complicated condition checks across all of our different states!

Going back to those awesome high tech range-finding binoculars from our example: Our NPC only uses them when they patrol. We made sure that the NPC puts them away when they leave the “Patrol State” by using the State Will Exit event receiver. No matter what state the NPC goes to next, those fancy binoculars are tucked safely away.


STATE MACHINES INSIDE STATE CHIPS

You can also nest state machines within state chips! Imagine we want states inside our Patrol State chip that decide if the NPC is walking or jogging when they are patrolling. Thanks to the state machine’s superpower, we can! 

When the Patrol State chip is active, its child chips are active too, including child State Machine chips and their children. It works all the way down the chip hierarchy.

Let’s get into how to do this.

  • Add a new State Machine chip inside the Patrol State chip and name it “Patrol Behavior State Machine”. 

  • Add an event called “NPC Jog” that we can use inside our new State Machine chip. 

Add a mechanism by which an NPC switches between jog and walk. Use a Random Int chip, an If chip, and an Equals chip to send the NPC Jog event randomly to the State chips inside our new State Machine chip. This will randomly tell the NPC to walk or jog!

Edit into our Patrol Behavior State Machine chip and rename the default State chip that’s already there to “Walk State”. This state is active by default, so our NPC walks while it patrols.

  • To make it possible to jog, add a new State chip and name it “Jog State”.

Within the Walk State chip, use the State did Enter and State Will Exit chip to make the NPC start walking when entering this state and stop walking before leaving this state. 

  • Add and configure an event receiver for the “NPC Jog” event. Conjure a State constant and connect it to a Go To State chip to transition from the walk state to the jog state. If the Random Int chip we set up earlier outputs a zero instead of a one, the “NPC Jog” event executes and we transition to the Jog state.

Now when our NPC is in the patrol state they either walk or jog while patrolling. Importantly, our other states still don’t need to worry at all about what happens when the NPC patrols. When the NPC is taking cover we don’t want them walking around! When the NPC is attacking we don’t want them to use their high-tech binoculars!

Since our states use the State Will Exit event to clean up the current state before leaving, we’ve made it easier to manage and create new functionality for our enemy NPC.


SYNCED STATE MACHINES

One last thing before you dive into creating your own state machines to make your functionality simpler to think about, manage, and expand on: state machines can be synced or unsynced. A synced state machine’s active state makes the experience consistent across all players in your room. Just use the configure tool on your State Machine chip and look for the Synced toggle. 

Quest 1 Support

Hey there, Rec Room fans!

We’ve received some support questions and feedback and wanted to confirm that we are no longer supporting Quest 1.

We understand that this news may come as a disappointment to players still using this platform. As a team, we're constantly striving to provide the best experience possible, and unfortunately, the age and technical limitations of Quest 1 have made it challenging for us to continue supporting it.

We want to thank all our Quest 1 players for being part of the Rec Room community, and we hope you'll continue to enjoy the game on our other supported platforms. We're committed to continuing to bring exciting updates and new features to Rec Room, and we can't wait to share what we have in store with all of you (especially something big later this year…)

Thank you for your understanding and continued support! Game on! 🎮😊

Rec Room on Xbox!

We’ve teased it, we’ve talked about it in AMAs… 

Today Rec Room is launching on Xbox! Please join us in welcoming a whole new group of players, family, and friends to the Rec Room universe 🌌 We’ve got a few events and surprises that should make the launch even more exciting: 

When you invite an Xbox player to try out Rec Room using your Friend Code you’ll both earn a free bottle of bubbly at the end of the event! 

We also built an awesome ^WelcomeXbox room where everyone (all platforms) can visit to meet all of the new players and earn a new limited time gift drop - the Space Soldier Helmet! Xbox players can also earn the gift drop by visiting the Rec Center. Be sure to visit the room before December 17th to grab the limited time gift drop! 

XboxPromo3.jpg

Bringing Rec Room to Xbox has been a ton of hard work and we couldn’t be prouder of the folks that made this happen. For us, Rec Room has always been about creating a fun and welcoming community for as many people as possible. That means making Rec Room the best place for you and your friends to hang out, regardless of location or device. 

Please help us welcome all of the new Xbox players in whatever way best suits your personality. If you’re a quest fanatic, party up with some Xbox players and show them the ropes on your favorite quest. If you’re a paintball fan show them your favorite map. If you’ve got a favorite batch of custom rooms, give them a tour! 

If you see players hitting any issues or having questions about Rec Room remember to let them know about our HappyFox support site. From there they can browse the knowledgebase or get in touch with the support team via a new ticket. We also have a very helpful and active player community on our discord for any quick questions.

New players can also find a lot of How To videos on our YouTube Channel or answered questions on our subreddit. You can find links to both of those and all of our other social channels and tutorials here

And a reminder for all players that your Rec Room account allows you to log into Rec Room across ALL supported devices! Your login works across everything: iPhone, iPad, PS4, PS5, Xbox, Steam, and Oculus. Every time we launch on a new platform we see a big wave of excitement hit the community as more people are able to have their first Rec Room experience. The community has been awesome at welcoming new players in each time this happens and we just want to say a huge thank you to everyone for that in the past and for all of that help going forward. Cheers! 

PS. If you capture a great Rec Room photo or video moment be sure to share it with us by tagging us in your post or using the #RecRoom tag. You can find us at:

@RecRoom on TikTok

@RecRoom on Instagram

@RecRoom on Twitter

Rec Room on YouTube

XboxPromo2.jpg