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 Rennat · Aug 02, 2011 at 08:19 PM · aipathingsimplepath

SimplePath instantiated AI

I just purchased SimplePath from the Unity asset store and I've hit a snag: When instantiating an enemy who has a PathAgentComponent I am immediately setting the m_pathManager to the scene's PathManager but still getting errors and no pathing behavior. The pathing works great if the enemy already exists in the editor but I'm having trouble getting enemies instantiated at runtime to work. Is there a solution to this?


edit

Since SimplePath is a system I paid for I don't think I'm allowed to post the code here but I think the root of the issue is needing to set a property on a behaviour after instantiation but before Awake is called. Is that possible or is there a common approach for this type of issue that I am just unfamiliar with?

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 BerggreenDK · Aug 02, 2011 at 10:35 PM 0
Share

would it be possible for you to contact the developer of SimplePath? I guess we wont see the inside code of it here, so I find it a bit hard to answer.

avatar image Rennat · Aug 02, 2011 at 10:40 PM 0
Share

I tried to find his email address but never did, I was hoping he would see this post. Since it's a paid library I can't post the code :/ (not sure of the exact legal rules here but I'm gonna play it safe and not post any of the code)

also see edit

avatar image Meltdown · May 10, 2012 at 09:44 AM 0
Share

Tanner did you ever resolve these issues? If so how did you? I can't seem to get an instantiated actor $$anonymous$$oveToPosition() successfully yet it works for a GameObject already in the scene.

avatar image Meltdown · May 14, 2012 at 05:28 AM 0
Share

Tanner I'm waiting on the developer to look at a simple instantiate problem I'm having with SimplePath. When he tells me what I'm doing wrong in the scene I'll post a download link here.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · May 14, 2012 at 01:10 AM

I'm pretty sure you can't do something before Awake - however, how about you get the prefab - change the variable in there and then do an Instantiate on it? That would mean the value was set before you instantiated the copy.

Given that instantiate just makes a copy of a GameObject - you have the GameObject that is your prefab, you can just change that in the code on the line before the Instantiate and then Instantiate will make a copy using the updated value.

Comment
Add comment · 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
0

Answer by whydoidoit · May 14, 2012 at 08:45 AM

To expand on my previous answer (which I'm doing because this does solve the general problem of setting a variable that needs to be used in Awake or changed before it is called for some reason).

Imagine you have a prefab that contains a reference to another object that is used in Awake:

 using UnityEngine;
 using System.Collections;
 
 public class DoSomethingInAwake : MonoBehaviour {

      public GameObject otherObject = null;
 
      void Awake ()
      {
          print (otherObject.name);
     
      }
 }
 


That is attached to a prefab - let's say it has null in the otherObject. Clearly this raises an exception when it is instantiated.

The following code could be used to initialise the value of otherObject in advance:

 public class InstantiateSomething : MonoBehaviour {
 
     public Transform prefab;
 
     // Use this for initialization
     void Start ()
     {
         //add these lines to update the value before instantiation
         var dsia = prefab.GetComponent<DoSomethingInAwake> ();
         dsia.otherObject = GameObject.Find ("Main Camera");
         //instantiate the updated prefab
   
         GameObject.Instantiate (prefab);
         //prints "Main Camera"
     
     }
 }

In your case you would change the GetComponent to return the path agent and set m_pathManager to your current path manager.

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 ctower2 · Jun 18, 2012 at 11:20 PM 0
Share

Thank you $$anonymous$$ike. I was having the same issue as the original post, and using this method I was able to get my problem fixed. $$anonymous$$y characters are now instantiating and using SimplePath correctly.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How Do I Make The Following Code Work 0 Answers

Pathing & Patrol AI Error 1 Answer

Astar Pathfinding - do not use last visited node 1 Answer

Is it possible to have a navmesh agent that ignores obstacles? 1 Answer

Which NavMeshSurface is a point (already on the NavMesh) on? 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