Forum rules - please read before posting.
Tech questions during the weekend? Drop in on the community Discord channel!

Hotspot custom script problem after Loading procedurally instanced saved assets.

So, I've been able to Save and Load with AC a procedurally generated hexgrid map.
The base of each visual hex, is made with the "Create new Hotspot" menu subtool. I add there the Remember transform, Component variables, Remember scripts, etc.
After I procedurally generate the map, I call the OnSpawn of the Remember transforms and individual ID are generated for them.
I added a hotspot mouse over script I steal from some part of this forum to send Component Variables to global variables, and then to a menu, that show hexes information on a menu. Then I use some Asset and Scene interactions to execute code and, for example, when I move to an hex, the hex record that is visited. (cleared, etc)

I save the game, loaded it, and all the map is in place and each hex remembers if is has been visited or not. So everything work, and that is great.

BUT, after loading, when hovering over the hexes, the mouse over hotspot script throws an exception, and doesn't comunicate the variables to the menu. (the variables work, the hexes have all component attached, etc):

This make me think that when the game is loaded, the hotspots are not "exactly" the same hotspots that are "registered in the state handler" (I don't know code, don't know if AC is how works, but looking in the Hotspot code in order to find another magic routine like the "OnSpawn", tried some things but can't. I'll never find what to do in my own. xD This is the code of the script:

`using UnityEngine;
using AC;

public class AdditionalHotspotInfo : MonoBehaviour
{
// public ActionList actionList;
// public ActionListAsset actionList;

    private Variables myVariables;
private Hotspot thisone;

    private string myVar1;
    private string myVar2;
    private bool myVar3;
    private bool myVar4;

private string infoString1;
private string infoString2;
private bool infoBool3;
private bool infoBool4;

// I put this start part trying to make revive the hotspot after the loading.
private void Start()
{

    //  EventManager.OnHotspotSelect += MySelect;
    // I put this part in a bad attempt to try to reassing Hotspots to the game logic when they appear again.
    // 
    if (KickStarter.stateHandler)

    {
        Hotspot thisone = gameObject.GetComponent<Hotspot>();
        KickStarter.stateHandler.Register(thisone);
    }

}

private void OnEnable()
{
    EventManager.OnHotspotSelect += MySelect;
}

private void OnDisable()
{
    EventManager.OnHotspotSelect += MySelect;
}

private void MySelect(Hotspot hotspot)
{
    if (GetComponent<Hotspot>() == hotspot)
    {
        //  actionList.Interact();

        Variables myVariables = gameObject.GetComponent<Variables>();

        GVar myVar1 = myVariables.GetVariable(0);
        GVar myVar2 = myVariables.GetVariable(1);
        GVar myVar3 = myVariables.GetVariable(2);
        GVar myVar4 = myVariables.GetVariable(3);

        GVar infoString1 = GlobalVariables.GetVariable(4);
        GVar infoString2 = GlobalVariables.GetVariable(5);
        GVar infoBool3 = GlobalVariables.GetVariable(6);
        GVar infoBool4 = GlobalVariables.GetVariable(7);

       infoString1.TextValue = myVar1.TextValue;
       infoString2.TextValue = myVar2.TextValue;
       infoBool3.BooleanValue = myVar3.BooleanValue;
       infoBool4.BooleanValue = myVar4.BooleanValue;



    }
}

}`

If I have to change something in this script, or do other stuff to the hotspots, please... Long day trying to make this work. Looks like the final piece to solve to keep developing the "engine" XD

I really don't understand why the script should work on a new start, but not after loading,

PS: The hotspots "Work" after the load. It read the basic hotspot information for AC menus, like the name. and if I click them execute code. What doesn't work is the script after Loading.

Comments

  • It looks like you're registering the event in OnDisable again. I'm not sure this is the whole issue, but it will at least contribute. Replace the line inside that function with:

    EventManager.OnHotspotSelect -= MySelect;
    
  • thanks! that worked. That part of the script was like that when I copied from here (I guess it would had other goal) so wouldn't never try changing that ;)

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!