Cannot adjust padding on game

Hello,

I am seeing some unexpected (to me) behavior regarding the game boundary padding on the laser defender course. I don’t like the quite generous padding that was achieved in the course by setting the padding value to 1.0f in the following code:

    _yMin = gameCamera.ViewportToWorldPoint(new Vector3(0, 0, 0)).y + _padding;
    _yMax = gameCamera.ViewportToWorldPoint(new Vector3(0, 1, 0)).y - _padding;

So, given it is a float value, I started decreasing the number to 0.5, 0.25, etc. However, decreasing padding had no effect whatsoever on the amount of padding in the game. So, I set the padding to 0.0f, which still achieves the exact same effect as padding at 1.0f. How does this happen? Deleting the padding results in no padding at all being applied. Why is an addition of 0 not the same as omitting the variable altogether? How can I achieve less padding than I currently have? Screenshot attached.

Thanks!

1 Like

Hello there!

I copied your code and I think I know what is going on.

I think the issue here is that you are modifying the value during Play Mode, Am I right? If that’s the case that’s why you are not seeing any changes, the boundaries are set in the Start method, since it gets called only once it means no matter how much you change the _padding value, the changes won’t be reflected in your game. What I’m saying is that you have to change the value before going into PlayMode, then enter PlayMode, then you’ll see a difference.

If you want to modify them during PlayMode you’ll have to call the SetBoundaries method in the Update method.

Hope this helps.

1 Like

Hi Yee,

Thanks so much for all your help today! Well, I have found the problem and I feel quite silly (but at least I have learned something). The problem is that I had serialized the padding field. Even though I knew that values adjusted in the Inspector would override code, I was under the impression that if I did not alter the values in the Inspector, the default script values would always prevail. I now know that this is not the case and if I serialize the field, I had better always adjust it in the Inspector. I probably should have realized something like this was occurring, but hey. I will in the future! Sorry for taking up your time, but thanks for your help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms