• 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 salex100m · Nov 07, 2013 at 03:00 AM · c#raycastlistswaypoint

List.Add(waypoints) broken? What am I missing?

Folks, I need some help! I can't get this stupid piece of code to work, even though I'm sure I had it working before....

All I'm trying to do is add my WayPoint object to my List of Waypoints... But for some reason, when I add this line of code "wayPoints.Add(temp);", the whole thing fails. If I comment out the line, everything else works (except my waypoint clones are all sitting around without a list to connect them)!

             if (mainCamPlane.Raycast(ray, out hitdist)) {
             
                 destinationPoint = ray.GetPoint(hitdist);
                 destinationPoint.y = 0;                
                 
                 WayPoint temp = (WayPoint) Instantiate(waypoint_orig, destinationPoint,Quaternion.identity);
                 wpAddToList = temp; //publicly exposed variable for testing...
                 
                 wayPoints.Add(temp); //the offending line
 
 
             }
Comment
Add comment · Show 1
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 hamstar · Nov 07, 2013 at 09:18 AM 0
Share

Are there any errors? Could you post the lines of code were wayPoints is declared/initialised?

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by salex100m · Nov 07, 2013 at 12:42 PM

Thanks for the reply.

No errors or anything like that. When I segregated this piece of code to post here, looks like it works independently.

So.... There must be something later on in my code that is clearing my queue in the same update. I'll have to add the rest of the script back into the segregated piece and see what's is doing it.

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 mattssonon · Nov 07, 2013 at 01:11 PM 0
Share

Please accept your answer or close the question.

avatar image
0

Answer by _MGB_ · Nov 07, 2013 at 01:46 PM

Did you create a new list before using it? i.e.

 wayPoints = new List<WayPoint>();

Yes, I forget to do this sometimes... ;)

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 salex100m · Nov 07, 2013 at 02:30 PM 0
Share

yeah everything works fine, except the list wont add anything. im pretty sure that it is adding now, just that later in the code it must be clearing the queue in the same update.

so my initial question is solved.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 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

Related Questions

Multiple Cars not working 1 Answer

Lists, Arrays and c# equivilent of js Array() 1 Answer

Distribute terrain in zones 3 Answers

Getting script to update list of transforms when destination reached or the transform's game object is inactive 0 Answers

Problem with raycast 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges