Search Unity

Portion of script only works properly when prefab is selected in the Assets folder

Discussion in 'Editor & General Support' started by Quasimofo, Jun 25, 2019.

  1. Quasimofo

    Quasimofo

    Joined:
    Oct 12, 2018
    Posts:
    1
    I'm having a somewhat bizarre problem. A specific function of one of my scripts is only functioning properly when I have the prefab it's attached to, Hook, selected in the Assets folder.



    The function is normally supposed to quickly shorten the spring joints forming the rope, propelling the player towards the grapple point before despawning the rope, but if the Hook prefab isn't selected, it only connects to the grapple point and quickly despawns without pulling the player. The problem started occurring within the last week, but unfortunately I'm not quite sure when it started happening and what changes I would have made around that time. As far as I can tell, every other part of my game is working fine, including all of the other functions in this script. The problem is still present when I build the game, so this is a major issue for me.

    I'll be the first to admit that I'm a very novice coder, so it wouldn't surprise me at all if I made some mistake that broke things, but I can't even begin to imagine how having the Hook prefab selected in the Assets folder would affect my script's function. Can anybody help me figure out what's going on here?

    EDIT:
    I figured out what my issue was! I had a timer controlling how long the rope applies force to the player, and I was decrementing it with a simple -- instead of using -= Time.deltaTime. Selecting the prefab caused the game to lag, which meant that the force was being applied to the player for a longer time. I've changed my script to use Time.deltaTime now, and it's working much more consistently! Just need to tweak settings to get it to behave exactly the way I want it to again.
     
    Last edited: Jun 26, 2019