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 awsome129 · Jan 27, 2017 at 12:56 AM · aipathfindingwaypointwaypointswaypoint system

Why isn't a Ai Waypoint Spawning???

I am making a Ai waypoint system. But a waypoint is not spawning in the scene, I don't know what i'm doing wrong. Please Help

 using UnityEngine;
 using System.Collections;
 
 public class AiWayPointManager : MonoBehaviour {
     
     float WayPointInstantiateTimer = 5;
     GameObject AiWayPoint;
     GameObject Ai;
     GameObject LastWaypoint;
 
     // Use this for initialization
     void Start () {
 
         AiWayPoint = Resources.Load("Waypoint") as GameObject;
         Ai = GameObject.Find("AI");
     }
 
     // Update is called once per frame
     void Update()
     {
         LastWaypoint = GameObject.FindWithTag("Waypoint");
         var LastWaypointPos = LastWaypoint.transform.position;
         var AiPos = Ai.transform.position;
 
         if (GameObject.FindWithTag("Waypoint") == null)
         {
            var SpawnWayPointAtStartOfLevel = Instantiate(AiWayPoint, AiPos + transform.forward * 2, transform.rotation) as GameObject;
         }
 
         WayPointInstantiateTimer -= Time.deltaTime;
 
         if (WayPointInstantiateTimer <= 2)
         {
             GameObject SpawnWayPoint = Instantiate(AiWayPoint, LastWaypointPos + transform.forward * 2, transform.rotation) as GameObject;
             WayPointInstantiateTimer = 5;
             Debug.Log(WayPointInstantiateTimer);
         }
 
         if (Vector3.Distance(transform.position, LastWaypointPos) <= 0)
         {
           //  AiOnWayPointPos();
         }
 
     }
 
     /*void AiOnWayPointPos()
      {
         gameObject.active = false;
      }*/
 }
 
Comment
Add comment · Show 9
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 juicyz · Jan 27, 2017 at 01:21 AM 0
Share

Are you getting any console errors?

avatar image awsome129 · Jan 27, 2017 at 02:48 AM 0
Share

thx for the comment. No I am not getting any errors.

avatar image GarretLawrence · Jan 27, 2017 at 04:41 AM 0
Share

Does the Console show anything?

If yes then you should look at the Hierarchy to see if there is new object spawned.

If there is a new object spawned then the problem is at "LastWaypointPos + transform.forward * 2" (spawned too far/too high/underground ...)

avatar image awsome129 · Jan 27, 2017 at 02:06 PM 0
Share

@GarretLawrence Thx for the comment. But no errors and in the hierarchy, the first waypoint is never spawning(SpawnWayPointAtStartOfLevel)

avatar image GarretLawrence awsome129 · Jan 27, 2017 at 02:41 PM 0
Share

Well... actually if this line

"LastWaypoint = GameObject.FindWithTag("Waypoint")"

return an object then no way

"GameObject.FindWithTag("Waypoint") == null"

avatar image awsome129 · Jan 27, 2017 at 05:54 PM 0
Share

@GarretLawrence can you elaborate on that last comment please?

avatar image GarretLawrence awsome129 · Jan 27, 2017 at 06:06 PM 0
Share

I meant if "GameObject.FindWithTag("Waypoint")" is null then system will throw null reference exception.

Because if it is null then LastWayPoint is also null, and when you try to access transform.position from a null GameObject (LastWayPoint) your code will break.

As you said, there is no error at all, so there must be a gameobject with "Waypoint" tag always exist from the beginning.

So there is no way for this line of code "var SpawnWayPointAtStartOfLevel = Instantiate(AiWayPoint, AiPos + transform.forward * 2, transform.rotation) as GameObject;" be executed.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

Sidescroller AI/Pathfinding/Flags/Waypoints 0 Answers

How do you move a character to another waypoint after landing on a specific waypoint 1 Answer

Make player follow a waypoint path but still be able to control player movement 1 Answer

Easy WayPoint System - Character climbing at waypoint 0 Answers

waypoint system help 1 Answer


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