Forum rules - please read before posting.

Object is getting scaled on load

I write a lot, ofcourse I hope to solve the problems myself as fast as I can but still. So now I have a loading problem. I have a turret in my game, turret gets killed and lands on the ground. I want to save the position of the gameobject, and that works fine. However my object gets scaled, I think I tried all options in the prefab: save scene preference and retain in prefab, some boxes ticked, others not, etc, and I read the manuel about this but I cant seem to save the object so it has exactly the same scale (the scale is not supposed to change at all!). @ChrisIceBox

Comments

  • Ok, its going better now. The object had a child but it hadnt have a constant ID and remember Transform script, after putting them there it worked. One thing: before I shoot the turret, I save the game, after the turret falls on the ground, I make another save game. I load savegame 1 and 2 and they load like they should. Nice! But if I where to shoot the turret and then load savegame 1 InGame, the
    turret fells immediately on the ground where it should be hanging (this is ofcourse because I have to use OnLoad). Not sure how to use OnLoad here. Prehaps parenting. Will try and check.
  • edited April 2015
    @ChrisIceBox I cant make OnLoad to work, and I have worked now on this since yesterday. I shoot a turret, turret falls on the ground, I load the game and it is still there. I made a variable to check and a cutscene to run and the variable moment is correct (when the turret falls I run an actionlist that puts it to false). I tried to manipulate the gravity on load, and there are changes but it doesnt work like how I want. The turret keeps stuck on load or keeps falling when loading the game where it supposed to be in place before he falls down.
  • void Update () {
    if(TurretHealth < 1 && canExplode == true){
    AC.AdvGame.RunActionListAsset(TurretBack);
    Instantiate(Explosion, transform.position, transform.rotation);
    TurretFall.transform.parent = null;
    TurretFall.GetComponent<Rigidbody>().isKinematic = false;
    TurretFall.GetComponent<Rigidbody>().useGravity = true;
    TurretFall.transform.Rotate(0,0,ZAxisCtrl * FallSpeed);
    canExplode = false;
    TurretFall.GetComponent<TurretScript>().canShoot = false;

    }


    }
  • So basically I use an ActionList Asset to set the bool to false. And this works. But the OnLoad Method is not called correctly.
  • imageimageI would like to share some screenshots but it asks for a link and I dont know how that works. Anyway, here is the code that I use for the gravity handling:

    public void SetGrav(){


    rb.isKinematic = true;
    rb.useGravity = false;

    }

    public void SetGrav2(){
    rb.isKinematic = false;
    rb.useGravity = true;
    }

    Thats all, unfortunately this doesnt get triggered at the right timing, which is caused by the ActionList. The ActionList should be running before or later after but I cant figure out how in this case.
  • The RememberTransform component will store the change in position, rotation, and scale.  You shouldn't have to resort to OnLoad for this, and I don't understand your code about amending the gravity, etc.

    The component will store the transform for the GameObject it's on *only* - so if anything else has moved, you'll need a Remember script for that as well.  I don't have enough information about the turret itself to advise anything more specific than that, but it sounds like there's more to it than just the position/scale of the turret model - are there any parent objects being transformed as well that also need to be saved?
  • Ok, the turret has a parent. When the turret dies, the parent is disabled and the object falls on the ground. I let the object fall by gravity, so at first the Rigidbody of the turret (the parent) is set to kinematic, but when it falls, it is set to gravity. So I think the problem here is the state change of the Rigidbody.
  • So yes Chris, the parented part of the turret (the canon) is the object where I am talking about.
  • edited April 2015
    Just to confirm: when I load the 2 different savegames from start, the object is in the right place. But when I play the game from start, save it, shoot the turret, and make another savegame and load savegame 1, the turret is for 2 frames using gravity and then switching back to kinematic which is not desired. I like to keep the state gravity OR kinematic. Does this sound as if I need to make a Remember Gravity script? @ChrisIceBox
  • (Basically remember the state of the Rigidbody)
  • Wow @ChrisIceBox, solved again! So I made a remember Rigidbody script on your instructions (the instructions on the site) and that was the solution. You really have an answer on any difficulty with AC Chris. I cant believe my eyes, thank you so much. In this script I could easily remember the isKinematic and useGravity states of the object.
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.