Hello, I have two blueprints for two different boats (Enemy1 and Enemy2), which are my enemies and I want to destroy them. The blueprints are the same, I only changed the name of the variables. When I only had one boat everything works, but when I put the second boat didn’t work anymore. The first boat doesn’t move and the second boat move too fast and far. The values are the same that the first boat. What can I do?
Thank you!
Okay, what I’m going to tell you is only to help you. This is very bad design and bad programming practice. In programing there is a term called DRY… Do Not Repeat Yourself, and for very good reason. As you duplicate code it becomes harder to maintain, prone to mistakes, and more involved to fix. If you change things or fix things in one place it means you have to do it in multiply places, which is not good, and just unnecessary.
Means these two blueprints are literally identical, you only need one. If the second one is going to extend the capabilities of the first, or just change the values of the variables then the second one should be a child blueprint that will automatically inherit all of the first code.
So with that, I of course recommend doing that first. Second your doing things on tick that you shouldn’t be. You can store the reference of game instance on begin play, this way you do not need to get it every tick and cast it each time.
Next, you are not providing enough information for anybody to really help. I do not see anything in your bp to cause an error. So I’m sure you probably do not have a variable set properly. But my recommendation would first be to fix the underlying foundational issue, Im sure that will help and if not it will make figuring out what is wrong much easier.
it appears that you are casting to the same gameinstance for both of them. Not entirely sure, but this may be the issue.
Doing what steve said will probably resolve this issue as well just because it’ll handle the casting differently.