I am trying to add my own code to a code from following a tutorial. The code is one line and as easy as: Destroy(gameObject, 3f); but this line of code creates a bug that cannot be fixed even though after deleting it. How can I avoid this bug? Do I have to modify the code from the tutorial I’ve been following to fix it? Is there actually a bug in unity that is unfixable and it is just best to avoid it?
depends on the code round it, what you think is making it not work. I havent checked but i think the 3f being seconds, would time scaled, so, if the game time is scaled to 0 it will never happen… if the code is in update in an if statements and the game object is disabled, its not going to run… so it depends exactly how to recreate this
“a bug” doesn’t mean anything. Is it playing random sounds? Is your mouse cursor upside down? Does running the game uninstall random programs?
You’re doing something wrong, but you haven’t given enough information for anyone to help you.
So you mean there is always a solution to bugs in unity? because I’ve been trying to find the problem for the last days, but even though I redo my actions, and deleted the script that I made when the bug happened, and reverted the situation back from when the bug was not yet occuring, the bug also occurred even though I deleted the actions that I made before it was occuring.
Here’s my previous post for the bug for more details: Vector2movetowards not working, 2D object staying in place
Hello, here is my previous post with the bug, I wrote the details in my replies:
Oh Jesus CHRIST almighty that tutorial has stuffed gameplay code into StateMachineBehaviours.
The problem is probably that you have a transition in there with a transition duration that’s not 0, so several StateMachineUpdates are running at the same time, but I wouldn’t fix that, I would learn to code in the standard way in Unity - behaviour code goes in MonoBehaviours, Animators only control animation, and you only break out StateMachineBehaviours if you need to post-process Animation to do IK or whatever, never to do gameplay state machines.
Or in other words, I’m sorry, but you’re following a garbage tutorial made by an amateur that probably shouldn’t be teaching anybody anything.
About a decade ago there was a Gamasutra post by our very own Joe Strout where he tried the combinations of logic present in:
- all code
- some code, some animation
- all animator state
It’s amusing and contains a survey of the issues.
Thank you sir, I understand now. He wasn’t supposed to put movetowards in the state machine behavior script. Alright I’ll just learn how to code the standard way, unity documentation and books is hard for me though. What way of learning path do you encourage for me to take, can you give me some resources, are free courses good, like code monkey, freecodecamp, and are there also good tutorials?
I honestly don’t know!
Sadly, while I can tell that a tutorial is good or bad by looking at it, I don’t actually know any good tutorials that I can recommend, simply because I don’t look at them much. I’ve been working professionally with this for 10 years, so beginners tutorials is simply not something I look for.
I do know that Unity Learn has quite a lot of things available for a bunch of different skill levels and topics, so that might be a place to start.
Remember that a tutorial is never going to teach you everything.
Remember also to scale your ambitions to your current level of comfort.
Learning has deep dynamic range of knowledge, ranging from knowing that the plus sign (+) does addition all the way up to the best way to organize a massive game and its back-end server.
Additionally because your brain is (most likely) a perfectly normal human brain, learning something once is never going to be enough. You may need to do something multiple times before it truly becomes part of your mental toolset.
This is why keeping the problem space small and going over it again and again is very useful when encountering a vast unknown knowledge space such as interactive software development.
Personally, I like the iterative approach that this guy uses. I find that it scales well to small sessions that gradually build upon each other.
Imphenzia: How Did I Learn To Make Games:
thank you for your help sir.
thank you, I understand.