Forum rules - please read before posting.

Prefabs, Run Instantly, Retain in prefab

Hey folks,

I've been through tutorials, and have been making an interactive door inspired by the Prefab Puzzle Logic one, based on the setup of the levers.

So I have a scene with two instances of the door prefab.

https://imgur.com/0YpnQDG

I have one isntance's IsOpen bool set to true, and one set to false.

https://imgur.com/4tBj2dO

I also have the ActionList Starter set to Run Instantly.

https://imgur.com/gNcsi6l

However, when I run the game, I get both doors open.

https://imgur.com/E0USHTQ

Everything operates well when there's only one door around. But when two doors show up, I get this confusion. Could this have to do with retaining the variable in the prefab (which I have unchecked)?

Also, related, in the tutorial the checkbox for retaining constant ID was unchecked, but I believe it's checked on by default. I've gone through and unchecked it on all the constant ID components (I think). I'm not sure if this makes a difference or not. What should I expect if I am retaining the id in the prefab? And if it's unchecked, am I not keeping track of IDs?

Any help and/or illumination would be appreciated. Thanks!

--Chris

Comments

  • "Retain ID in prefab?" will cause the ID value to be non-zero for the prefab itself.

    Generally, this should be checked in the case that you have a single instance present in multiple scenes. If a prefab has an ID, then that ID will be shared with scene instances - meaning you can make use of that ID to refer to the scene instance regardless of which scene you happen to be in.

    In the case of having multiple instances in a single, you'll want to make sure that this is unchecked. If a prefab has an ID of zero, then a new ID will be generated for each instance of it. The workflow you mention requires that each instance of the prefab has a unique ID number that can be used to tell them apart.

    Unchecking this box after placing instances in the scene, however, won't affect scene instances retroactively - you'll need to double-check that each instance has a unique set of ID values.

    If both doors are opening, check that the "Door Variable" objects both have unique IDs, and that the parameters in the ActionList Starter component are assigned to the scene object - not the original prefab. You can reset the Constant ID component to generate a new ID if necessary.

    I'm only speaking generally here, though, as the workflow in the screenshots you've shared look OK. If the above doesn't help, share images of the "Door_Interactive_Move" ActionList as well as the Inspectors of the two doors so that I can see the specifics of your situation.

  • Ok interesting. So a couple of observations:

    1) One thing I'm surprised by: I'm having a really hard time convincing the prefab's main Constant ID component's "Retain in Prefab" checkbox to remain unchecked. In prefab mode, I uncheck it, save, and then exit prefab mode, then return to editing said prefab and the box is checked once again. It really does not want to cooperate. Is this expected behavior?

    I can uncheck it as an override in scene. I realized the IDs were in fact the same on the two doors. My bad. So I managed to make them different by deleting one, unchecking the "retain in Prefab" box on the remaining one, and then dropping in a new one (and unchecking the box).

    Now that the two doors are not telepathically linked, I can open one and not the other. Success!

    2) However, if I manually override one's DoorOpen variable to be true (default is false), the ActionList Starter doesn't seem to be working. When I run the scene, both are closed, though I would expect one to be open. If I then go manually run the DoorMove ActionList (while the game is running), the overridden one wakes up and opens. I would love suggestions as to what's going wrong here.

    3) Speaking of ActionList Starters, I notice that the Run Instantly checkbox only seems to work if the interaction Pauses Gameplay. But I'm making a first person project, and wouldn't expect an interaction as common as a door opening to pause gameplay. If I understand this correctly, scenes with doors that start open and don't pause gameplay will, when the scene starts running, animate open visibly, like actors late to their marks after the curtain rises. Is there another method I'm missing?

    Thanks so much for the help so far. This seems like such a powerful system and this simple door has proven to be a good learning opportunity. I feel like I've hit all the bumps in the road (in a good way).

    --Chris

  • edited May 2022

    In prefab mode, I uncheck it, save, and then exit prefab mode, then return to editing said prefab and the box is checked once again.

    That's certainly not expected behaviour - though I cannot recreate it. What are your AC and Unity versions?

    if I manually override one's DoorOpen variable to be true (default is false), the ActionList Starter doesn't seem to be working.

    Sorry, can you elaborate on this? I'm unclear of the difference between what you're doing here, and the screenshots above where the doors are opening on start.

    Speaking of ActionList Starters, I notice that the Run Instantly checkbox only seems to work if the interaction Pauses Gameplay

    The ActionList Starter's Run Instantly option works by "skipping" the ActionList involved. This feature of ActionLists is only available for those that block gameplay - since it works by skipping all Actions (and chains of subsequent ActionLists) until gameplay resumes.

    Though, since the ActionList Starter is set to run as the scene initialises, having it block gameplay while it runs instantly wouldn't normally be noticeable. Are you having it run instantly during gameplay, after the scene has initialised?

    An alternative to this option would be to introduce another parameter, e.g. a "Run Instant" bool that is used by the ActionList to control how the door itself is animated.

  • That's certainly not expected behaviour - though I cannot recreate it. What are your AC and Unity versions?

    Oh, right I should have mentioned all that at the start. I'm on Unity 2021.1.6f1 and AC V1.75.2.

    So, the checkbox not being saved...here's an image of what I'm seeing on my end:

    Imgur

    As you can see I just check the box, save, exit and re-enter edit mode and that change has been forgotten. I'm not sure what else to do...maybe I should upgrade to the newer AC version?

    Sorry, can you elaborate on this? I'm unclear of the difference between what you're doing here, and the screenshots above where the doors are opening on start.

    I was unclear earlier. I took your advice and made sure both doors had different IDs. This solved my "both doors do the same thing" problem. This was my biggest blocker.

    Now I'm working on scene setup, meaning I'd like to have the ability to have some doors open by default. And, ideally, some locked by default...but I haven't crossed that bridge yet.

    In the scene, locally overrode one door to be DoorOpen true and one false (the default). My expectation was that when the game started I would have one open and one closed door. This was not the case. On start, both are closed. I assumed the ActionList Starter component would run and tell these doors to get into position.

    In the Prefab Logic Puzzle tutorial, this is what happens with the two levers. But I'm not seeing the same results. Is there a step I'm missing to "jiggle the handle" as it were and get these guys to wake up?

    Though, since the ActionList Starter is set to run as the scene initialises, having it block gameplay while it runs instantly wouldn't normally be noticeable. Are you having it run instantly during gameplay, after the scene has initialised?

    I'm not doing anything fancy. I'm just running the scene. All interactions in question are set to be "pause gameplay" because I wanted to be able to have some doors open by default.

    An alternative to this option would be to introduce another parameter, e.g. a "Run Instant" bool that is used by the ActionList to control how the door itself is animated.

    In theory, I would like to find a way to have prefabs behave this way...starting in either state...but have them also not block gameplay as that seems a little heavyhanded when playing the game in first person. I'd like to investigate this option, though I'm unclear on how I would get them to actually run instantly. Is there a setup step other than the actionList starter?

    Thank you!

  • edited May 2022

    As you can see I just check the box, save, exit and re-enter edit mode and that change has been forgotten.

    Thank you - it looks like this might be related to the "Auto Save" box being unchecked. I will look into this.

    As a side note: it's not necessary to have both a Constant ID and Remember component on the same object - since Remember components serve the same purpose. You should be free to remove Constant ID from the prefab here.

    On start, both are closed. I assumed the ActionList Starter component would run and tell these doors to get into position.

    That should be the expected behaviour. If you click the button to the top-right of the ActionList Starter component at runtime, choose "Run now" from the menu - does that cause it to open correctly?

    I'd like to investigate this option, though I'm unclear on how I would get them to actually run instantly.

    It depends on how you're moving them - are you using animation, or AC's "Object: Transform" Action?

    If you're using Animation, you'd likely have to introduce a Trigger parameter (named e.g. "ForceOpen" that is used to transition to the fully-opened animation state when invoked.

  • That should be the expected behaviour. If you click the button to the top-right of the ActionList Starter component at runtime, choose "Run now" from the menu - does that cause it to open correctly?

    Yup.

    It depends on how you're moving them - are you using animation, or AC's "Object: Transform" Action?

    I'm using Object: Transform, match to maker....following the setup of those levers from the tutorial.

    Ok here's a clue about the strangeness I'm seeing. I deleted one door and the door behaves correctly (set IsOpen variable to true and door starts opened). I then duped that door and now both doors begin open. I then set one door to false, and now both start closed.

    When I delete one door and have only one in the scene, it behaves correctly.

    I also removed the constant ID from the main door, leaving the Remember Variables, since you said this was duplicated logic.

    Somehow Unity is still having a hard time differentiating between the doors. Even though they have unique IDs, none of the Constant ID components (on the various markers or hotbox for the Use Interaction) have "retain in prefab" checked, and all actionlists are using scene instances, not prefabs. I don't know how to convince AC/Unity that these guys are not telepathic twins.

    I'm trying to get to a point where I have gameplay prefabs with internal logic I can just drop around in scenes. Doors, desks with drawers, what have you. To use as building blocks. This prefab approach seems like the right one, but maybe not? Maybe there's a better tutorial for this? In the First Person Primer, it felt like most of the logic just lived on instances in the scene....not wrapped in a prefab. But any advice about approach would be appreciated!

  • I'm using Object: Transform

    In that case, you can either create a Float parameter that's mapped to this Action's "Transition time" field, or a Boolean that causes a copy of this Action with a time of zero to run instead.

    Somehow Unity is still having a hard time differentiating between the doors.

    I can't tell any issue with your workflow - things should be working, from what you describe. I'll need to see this for myself to be able to know whether this is a workflow or AC issue.

    Can you PM me a .unitypackage that includes your scene, door prefab/graphics and related ActionList asset files?

  • Absolutely. Sent.

    In that case, you can either create a Float parameter that's mapped to this Action's "Transition time" field, or a Boolean that causes a copy of this Action with a time of zero to run instead.

    I'm a little hazy on how to create a setup actionlist instead of an interact actionlist, which it seems like this would require. Is there a good example of this somewhere?

  • I'm a little hazy on how to create a setup actionlist instead of an interact actionlist, which it seems like this would require.

    I'm not suggesting you create any new ActionLists - just modify the one you're already using.

    Your Door_Interactive_Move asset has four parameters defined already - a new parameter would be added as a fifth, and then used to control how the "Object: Transform" Action is used.

    I will see if I can demonstrate this with the package you sent.

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.