Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MajorSmurf · Sep 04, 2018 at 12:41 PM · prefaberror messagenavigation

Pathfinding script breaking for prefabs only

OK so I've had a really annoying problem for the last three days and I've finally nailed down the problem but not sure how to fix it. I have used a youtube tutorial series by Sebastain Lague on creating your own path-finding which works amazingly well and I wanted to create my own target selection to find the closest target and set that as the target for the path-finding to use which i have set up and works fine. I than created a Spawner script but any enemy created through this script the path-finding will only work for the first target it finds to be the closest if the player or another object becomes the closest it selects that as the target but refuses to move towards it or use path-finding at all.

So my question is simple why does this work for objects that ain't prefabs. I myself can't imagine something working fine for just a gameobject in the level at the start and one that I spawned in during the game. This is the part that is the confusing to me as all the objects are the same and if i just duplicate an enemy it will work fine but instantiate one in and i get an error. The only clue I have is an error which shows the following:

alt text

If you want to see the spawner script and other scripts affected I have a unity forums thread with them all shown listed below:

https://forum.unity.com/threads/dynamic-path-finding-script-having-problems.549877/

unityerror3.png (67.5 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MajorSmurf · Sep 04, 2018 at 08:50 PM 0
Share

So completely forgot to thank anyone who can help me with this problem thank you for any help given :3.

avatar image toddisarockstar · Sep 04, 2018 at 10:43 PM 0
Share

that error means that in your code you are accessing a variable before it is filled. in your case i would guess your pathfinding script is trying to access a Gameobject variable before it is asigned to something.

make sure all your spawning scripts are finished running, before you run your pathfinding script.

avatar image MajorSmurf toddisarockstar · Sep 05, 2018 at 12:00 AM 0
Share

How would go about doing that? sounds like a decent fix if i knew how to do it xD. I know you can change the order in which scripts are executed but does doing that only apply to scripts when the game is first built/started?

So let me phrase that better if I put the targetSelection script before the unit script would it would apply once or would targetSelection always be executed first even through the update function etc.

p.s. thanks for the reply I want to thank you for supporting me :3

edit: 2 had a brainwave just now.... could we also be talking a simple bool check that's set to false in till after the object is instantiated and switch it to true on the pathfinding script when finding a path?

avatar image MajorSmurf toddisarockstar · Sep 05, 2018 at 03:32 PM 0
Share

@toddisarockstar I want to thank you I've now sorted the problem mostly it doesn't work as quite as intended but you put my on the right thought path so thank you very much. All of them are now dynamically switching targets whether they are prefabs or not. It was rather simple once you told me what the error was. So thank you for helping me out :3

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by telecaster · Sep 04, 2018 at 10:33 PM

Sorry for the dumb question, but is pooling an option? That way all targets are in the scene, but not active? Or maybe I am just missing the issue.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MajorSmurf · Sep 05, 2018 at 12:03 AM 0
Share

Wouldn't I still get an error as it would still become active like if i instantiated it or am I mis-understanding what pooling is? I know its to store gameobjects to reduce lag etc via having them in the world already but wouldn't I still get the error as pooling still needs to refresh the list or array of gameobjects or am I talking nonsense?

I also want to make it clear that the AI in the level work fine with no errors or anything it only applies to ones that are created through Instantiated objects so I'm not sure if pooling is a fix as I might still get the error but anything is worth a try at this point :3 so ill have a look into pooling when I get a chance to.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

120 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Prefab Position 2 Answers

Instantiating a prefab with navmeshagent 1 Answer

Rotation Issues error CS1612:,Can't edit rotation (error CS1612) 1 Answer

Clone of prefabs copy original´s script state during runtime? 0 Answers

What is this error: "TLS Allocator ALLOC_TEMP_THREAD, underlying allocator ALLOC_TEMP_THREAD has unfreed allocations" and how to fix it? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges