Forum rules - please read before posting.

Lever position Logic prefabs

Hello all

I'm new to the adventure creator but not new to unity and I'm not much of a coder...but i'm trying. So I went through most of the video tutorials on this site to get my head around how AC works and it is a pretty amazing tool and I'm already building out my scenes. I did the Logic prefab tutorial and everything makes sense for the most part, but my issue is the Boolean. I know it is true or false, on or off. So that is why the basic lever on and lever off work with this setup. I am trying to figure out how to use 3, 4.. even 7 levers and I want the levers to have 3, 4, or 7 positions. I've been trying to mimic the setup with different parameters with no luck.

I feel like I'm supposed to use an int or string so it can test 1,2,3,4... options but I don't understand the looping of it i guess.

I looked at this post

I did what he did and created a hotspot that could change the color of an object to what ever color. I set it up to change 4 options. No problem click on the hotspot and it cycles through the colors. So I figured I could do the same but for the Object transform instead of Material. But I don't understand how to make it a prefab like the logic prefab example.

I know this is possible. Any help would be appreciated. Thanks in advance.


  • Welcome to the community, @astraldesign303.

    I recommend first getting the behaviour right before placing everything in prefabs. So long as you rely on ActionList assets, and component Variables, moving things to prefabs afterwards shouldn't too much of a hassle, but it's important to get things working right with just the one scene instance first.

    You're right that an Int variable would be the best choice. If you want to cycle through the different configurations (i.e. clicking when the lever is in position 2 causes it to move to position to 3, etc), you can use the Variable: Set Action's Increase By Value option to increase the Integer by 1 each time. To have it reset to zero if you exceed the number of positions (e.g. it becomes 4 when it only 3 positions), you can use the Variable: Check Action to check if it's greater than 3, and then use another Variable: Set Action to set it to zero.

    When you mention 3, 4 or 7 positions, do you mean that you want to have three different types of levers, each with a different possible number of configurations? If so, you could make use of another Integer variable named "Max Positions", that you can use to set how many positions the lever can have. The Variable: Check Action can also be used to compare two variables, so you could instead compare your "current position" int to your "max positions" int in the Variable: Check Action I mentioned above.

    When it comes to visualising what position the lever is in, it can be a bit tricky to set an object's position manually when dealing with so many possible positions. Personally, I'd make use of animation to animate the lever instead.

    For example, let's say the lever has 4 possible positions. Attach an Animator to it, and assign 4 different animations (one for each position). Create an Integer parameter in your Animator Controller, and use this to transition to each of the 4 animations based on its value (so a value of "0" goes to the first position, "1" to the second, etc).

    What you can then do is attach a simple script to sync up the Animator parameter value with the "current position" Component Integer variable. Something like this should do it:

    using UnityEngine;
    using AC;
    public class SyncAnimParameter : MonoBehaviour
        public Animator _animator;
        public string animParameterName = "Position";
        public Variables variables;
        private GVar variable;
        private void Start ()
            variable = variables.GetVariable (animParameterName);
        private void Update ()
            _animator.SetInteger (animParameterName, variable.IntegerValue);

    To use it, paste in a C# file named SyncAnimParameter.cs, attach to your lever, and fill in the fields - naming both your Animator Integer parameter, and your "current position" Component Integer as "Position".

    As there's quite a lot to go through here, let's see some screenshots if you have trouble with any of it. Images can be posted to e.g. and links pasted here.

  • Thanks for your quick response. I'll post my progress and update with my solution
  • edited May 2021

    I figured it out! Thanks again Chris for your detailed response. I used it to get a better understanding of what I needed to do. I'm really excited about solving this problem. I almost gave up and was looking at other puzzle prefab assets in the unity asset store but they looked so similar and all based on the same basic logic, click and move the spinner, lever, color, etc...with this base you can create all of the same puzzles with the same 3 ActionsLists. All you need to do is change the Objects, positions, and function. I'll do my best to explain.

    The top image is the DoorMOVE(Unlock Puzzle) action list and is the answer to the puzzle. This is the base I was looking for with my initial question. This can be changed to any number 3,4..7 Levers where it is checking the position of the Object. If they are all at position 1 in this case the door opens.

    The second image is LeverMove(Puzzle Object Move). Similar to your variable check, but it is looking for the integer. If it finds position 1 it moves there, if not moves to 2, and then to 3. Again can be any number of positions.

    The third image is LeverUSE(Puzzle Hotspot Interaction) which is the most complex and I didn't fit the bottom of the visual script in the picture because it is the same as the 2 lever example on the tutorial. The main difference is My variable check is again looking for the integer. If it sees 1 it moves to 2 and then 2 moves to 3... and then on 3 it loops back to 1. So this could be set for multiple positions.

    In the ActionsList:Run at the bottom you just have to include as many Lever Variables and positions you have for the puzzle.

  • Great stuff, thanks for the update!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.