• Hi Guest!

    We are extremely excited to announce the release of our first Beta for VaM2, the next generation of Virt-A-Mate which is currently in development.
    To participate in the Beta, a subscription to the Entertainer or Creator Tier is required. Once subscribed, download instructions can be found here.

    Click here for information and guides regarding the VaM2 beta. Join our Discord server for more announcements and community discussion about VaM2.

Solved Switching from Edit Mode (E) to Play Mode (P) with a Button or Trigger

CheersMate

Well-known member
Joined
Sep 5, 2022
Messages
234
Solutions
4
Reactions
827
Is there a way to switch from Edit Mode (E) to Play Mode (P) with a Button or Trigger?
 
Solution
You realize that you can switch by hotkeys P and E on your keyboard, right?

Then there is my EditMode plugin (part of Essentials) that you can setup as Session plugin, so VaM goes to Edit mode whenever you load a scene.

If you really want triggers, it should be easy to make yourself a little plugin that exposes the function as trigger, which you then can use from a UIButton or whatever in your scene:
C#:
using UnityEngine;

namespace MacGruber
{
    public class PlayEditModeTrigger : MVRScript
    { 
        public override void Init()
        {
            SetupAction("PlayMode", OnPlayMode);
            SetupAction("EditMode", OnEditMode);
        }
              
        private void OnPlayMode()
        {...
You realize that you can switch by hotkeys P and E on your keyboard, right?

Then there is my EditMode plugin (part of Essentials) that you can setup as Session plugin, so VaM goes to Edit mode whenever you load a scene.

If you really want triggers, it should be easy to make yourself a little plugin that exposes the function as trigger, which you then can use from a UIButton or whatever in your scene:
C#:
using UnityEngine;

namespace MacGruber
{
    public class PlayEditModeTrigger : MVRScript
    { 
        public override void Init()
        {
            SetupAction("PlayMode", OnPlayMode);
            SetupAction("EditMode", OnEditMode);
        }
              
        private void OnPlayMode()
        {
            SuperController.singleton.gameMode = SuperController.GameMode.Play;
        }
      
        private void OnEditMode()
        {
            SuperController.singleton.gameMode = SuperController.GameMode.Edit;
        }
      
        public void SetupAction(string name, JSONStorableAction.ActionCallback callback)
        {
            JSONStorableAction action = new JSONStorableAction(name, callback);
            RegisterAction(action);
        }
    }
}
 
Upvote 0
Solution
Amazing. Thanks! Plus, this would be a good dipping of the toe into plugin creation for me.

History:
In my scene I'm using the TriggerUI plugin to open the appearance menu to select custom looks and of course when this happens it automatically switches to Edit Mode. My thought was that it would be good to automatically switch back to Play mode when exiting the "Select Look" portion of the scene and returning to the main scene. It's probably not ideal to switch a user unexpectedly from Edit to Play so maybe if I make my own plugin I'll capture the state before triggering Appearance menu restore that upon exit.

Again, thanks for the code snippet.
 
Upvote 0
Back
Top Bottom