Forum rules - please read before posting.

Save game only saves 1st instance of a prefab.

I'm making a sandbox model railroading game where the player can place different track sections to design their own track plan. I attached the 'Remember Transform" script but only the first instance of a track section is actually saved. Here's the instantiation code:

if (Input.GetMouseButtonUp(1))
{
Vector2 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
trackStraightHolder = Instantiate(trackStraightPrefab, worldPosition, Quaternion.identity);
trackStraightPlaced.Add(trackStraightHolder);
}

See link for images...

Thank you!

shastastudios.homesteadcloud.com/Support

Comments

  • Welcome to the community, @shastice.

    You'll need to call the RememberTransform script's OnSpawn function if you're spawning such an object through code, as opposed to the "Object: Add or remove" Action.

    Try this:

    if (Input.GetMouseButtonUp(1))
    {
        Vector2 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        trackStraightHolder = Instantiate(trackStraightPrefab, worldPosition, Quaternion.identity);
        trackStraightPlaced.Add(trackStraightHolder);
        trackStraightHolder.GetComponent <AC.RememberTransform>().OnSpawn ();
    }
    
  • Easy fix...Right on. The prompt response is much appreciated. Thank you!

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.