Forum rules - please read before posting.

Object component variable that works across scene?

Hello, there are some variables that I would like to use for 2 to 3 scenes, but I think best not to put as Global variables (as Global variables are best for usage through the whole game). So I tried to use the object component variables, and put the object as a prefab, with Don't Destroy on Load on the object. But it seems in the next scene the actionlists cannot catch the object component variables. Is such function not available for prefabs? Are there ways to work around it?

Thanks.

Comments

  • What ActionLists are these? ActionList assets?

    The Variables would need to have a ConstantID value to be recognised by assets, but this should be the case already because the Remember Variables component needs to be attached for saving to work.

    Having such an object survive scene changes would cause issues, however there is an alternative trick that involves having an instance of the prefab present in both scenes, and transferring saved data between them upon loading the scene.

    Such a trick is used for creating a "global" Conversation here: https://adventure-creator.fandom.com/wiki/Creating_a_global_Conversation

    I expect something similar could be done for Variables, by replacing mentions of "RememberConversation" with "RememberVariables".

  • I am trying the above method. But may I ask how to change the values of Component Variables by script? When I do GetComponent<AC.Variables>() it seems to have no suitable methods to set* and **get the variable values.

    My AC version is 1.68.3, thanks.

  • Oh I got it, it is GetComponent ().GetVariable (id).IntegerValue;

  • I mean GetComponent (AC.Variables).GetVariable (_id).IntegerValue;

  • And the above method works! Thanks!

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.
Do NOT follow this link or you will be banned from the site!