- Home /
Wierdest bug ever!! (pls help!)
Ok, so this is regarding a grid based game I'm working on, in which the object translates in the direction inputted by the user until it collides with an object.
Some tiles of the grid don't have objects, but they are interactable, such as bonus point tiles, teleportation tiles, next level load tiles, and tiles that are empty (fall through them).
Now this bug I'm about to tell you about occurs with the "interactable tiles". When I load a scene for the first time, they all work perfectly fine just the way I want them to. If you go to an empty tile, you fall through; if you hit a bonus tile, you get bonus points, etc. Now let's say I build and run my whole project, and load level 1. Assume, level 2 has some or the other "interactable tile". I play through level 1, and as soon as I get to level 2, the interactables start acting buggy. Sometimes they don't work at all, sometimes they work, its very random. And then, when I open level 2 again by manually opening its scene, the interactables WONT work. But if I delete the interactable tiles, and replace them with a new prefab of the same tile type... It works perfectly. Then when I load again via building and playing from a previous level, it stops working again. I can repeat this process a million times and haven't found the solution. Rather, I haven't even understood the problem and WHY I am getting it.
Please help out and let me know if you have any idea as to what might be going wrong. Even if you don't have a solution at least let me have your view as to what the problem might be caused by. Would really appreciate your answers to this really really really unusual bug!
I haven't used static anywhere, except for the index of the current level. That is, static int currentlevel. It starts from 0 and goes all the way upto the last level index.
I say static variables because it sounds like persistent data ruining your day.
Either that or you are not instantiating your prefabs correctly. This is why dragging them in to scene appears to work.
Some tiles of the grid don't have objects, but they are interactable
If it's not in the hierarchy its not in the game. You can reference scripts and components of prefabs but you need to instantiate a gameobject for it to do what you want In Game.
$$anonymous$$y initial hunch was similar to meat5000.
Seeing as that is not the case, you are modifying the variables in your prefab directly. Remeber to only modify the "instance" that you created via "instantiate". Generally, people will unwittingly modify the original prefab, despite instantiating.
In short, if you have a public variable like public gameObject aPrefab;
then you say newObject = Instantiate(aPrefab...)
...
Remember to always modify newObject, not aPrefab
This is essentially the same question, right? You will probably need to close one of them if so.