Forum rules - please read before posting.

ConstantID + Actionlist asset parameter

edited December 2023 in Technical Q&A

I have a short actionlist asset for opening/closing containers in the appropriate menu. First it checks if the menu is open (and closes it) or closed (and opens it). Then it also plays a couple of different animations.

I set up two parameters: a string one for the menu name, and a gameobject one for the container. It works well, except for the fact that when you set the actionlist asset's parameters from a scene cutscene, it doesn't really save the ConstantID of the object. The thing is - it sort of does, but doesn't. Let me explain.

My container is a child of the player prefab. If I add the player to the scene, assign the container, and then deactivate the entire player object (but leave it in the scene), then when I run the game the container that the custscene opens is the correct one under DontDestroyOnLoad! The deactivated one in the scene hierarchy remains unused. So AC must be reading and using the ConstantID to do that.

But if I actually delete the player object from the scene after assigning the container, then instead of retaining the ConstantID (as it would have done if I had used the Open action directly), the custscene simply loses the parameter assigned.

During development I actually generally keep the deactivated player in the scene just so I can easily assign stuff. This almost always works, so I have nothing against keeping it there, but I've noticed that sometimes (rarely) the component variables that are also children of the deactivated player are affected by actions instead of the activated player under DontDestroyOnLoad. So, say, if I set a bool to true, the deactivated component variable will change to true, but then a check of the same variable might return false because the activated component on DontDestroyOnLoad will be checked instead. This is rare, and I haven't been able to pinpoint under which circumstances this happens exactly, but simply reopening the cutscene editor and closing it seems to fix the connection to the correct object under DontDestroyOnLoad.

Still, I was planning on deleting the player from the scene once I was mostly done with development, to avoid breaking this link to the variables. The thing is that now I can't do that because it would break the link to my containers.

Is there a way to retain the ConstantiD for parameters?

Comments

  • I'll attempt a recreation. To be clear: it's your scene-based Cutscene that's running an ActionList: Run Action to set the parameters of the Actionlist asset?

  • edited December 2023

    It is, yes! In the editor, if I keep the scene-based cutscene open and delete the player object from the scene, I can see the ActionList: Run action switching the assigned parameter from the container object to 'missing'. And then If I click play, the field will display 'none' rather the object with the constant ID that AC has just instantiated via the player prefab. Running the actionlist confirms the error: the menu displays the contents of the player inventory instead of the container.

    Using the Container > Open action directly in the scene-based cutscene does seem to save the ConstantID correctly. It's only when we are using it indirectly via an actionlist asset with parameters that we run into this problem.

  • Rather than placing the Player temporarily in the scene, try locking the Cutscene's Inspector and then opening the Player in prefab mode so that you can assign the Container's "source" prefab into the Cutscene field - does it then work?

  • edited December 2023

    It doesn't. As soon as I close the prefab, the field says the object is 'missing'. And if I reopen the prefab, the object is still shown as missing (unlike what happens when AC has saved the ConstantID). When I run the game, the field changes to "None", and the menu opens the player inventory instead of the container.

    Also, one interesting thing about the way this works when the deactivated player is left in the scene is that if I click Play, open the actionlist and click on the object in the field, then the deactivated container is highlighted in the hierarchy. But the inspector shows that this container is empty, while the container parented to player under DontDestroyOnLoad contains all the correct items. And when I run the actionlist and drag items into and out of the container, it's definitely the DontDestroyOnLoad container that is updated.

    So it appears to me that this is happening (I didn't look into the code to make sure, but it's what the behaviour points to):

    1. When the game is running, AC checks for the object assigned to the field and retrieves its ConstantID, whether that object is active or not.
    2. When the action runs, instead of using that direct reference, AC will iterate through the hierarchy and find an active object with the same ConstantID to open.

    In short: the 'Run Actionlist' action has no mechanism through which it will save a set parameter's ConstantID. It will only take direct references to a scene object, and it will lose the reference if the object is no longer in the scene/when the prefab is closed. BUT when the game is running, if the referenced object is still in the scene (even if not active), it will get its ConstantID and try to run the action on the active object it finds with that ConstantID, instead of doing it directly.

  • Thanks for the details - I've recreated the issue.

    Generally speaking, the behaviour you're pointing to is correct: if a GameObject field connection gets broken, but a CID value is recorded, then AC will search for objects in the scene with that CID.

    Given the various fields/assets/cutscenes/prefabs/local objects etc that can all potentially be involved - there are a few permutations that need to be accounted for - but the specific case you've found wasn't factored in.

    As part of the next release, AC will check if you are attempting to assign a prefab GameObject parameter in a scene-based ActionList: Run Action. If so, you'll be given the option to either reference the original prefab at all times, or the runtime scene-instance of it. Selecting the latter will record the CID and allow it to be referenced properly at runtime.

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.