Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 bobatismo · Jul 19, 2014 at 07:18 AM · transform.positionpublic static

public static transform waypoints problem

My code checks the character's tag and then assigns a time-scheduled route of waypoints to follow. I tested this with a few characters and a few waypoints and it worked perfectly.

To be clear: My "game clock" would say it's 5pm, and the character would leave work for the bar. Then at 8pm they'd go home for dinner. At midnight, they'd sleep. At 8am, they'd wake up and then at 9am they'd go to work and it would keep repeating.

Now I want to use more waypoints and characters.

But the idea of dragging 50 waypoint game objects to each character so that they all know how to navigate the map seems silly.

My solution was to have a single game object containing the reference to all of the waypoints, as public static Transform waypoint01, public static Transform waypoint02, etc.

I thought this was pretty brilliant on my part (as a total novice) but it doesn't work. I get a NullReferenceException error: object reference not set to an instance of an object, at line 18, which is where I set the initial value before letting each character overwrite it depending on their schedule.

 Line 18: Vector3 waypoint = WaypointLocations.waypoint01.position;

I did some searching around and it seems like my problem is that I can't (or shouldn't) use public static transforms the way I'm doing. Does anyone know either a quick fix to make what I have work, or know what a more proper solution is?

Comment
Add comment · Show 3
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 bobatismo · Jul 19, 2014 at 04:29 AM 0
Share

As an alternative, I tried declaring the script from the other object (public WaypointLocations WP), then using Vector3 waypoint = WP.waypoint01.position; and, while it compiles, I am getting the same error and it's not working.

avatar image Kiwasi · Jul 19, 2014 at 07:38 AM 0
Share

Have you considered using a static List ins$$anonymous$$d?

avatar image tanoshimi · Jul 19, 2014 at 08:52 AM 0
Share

Have you made the WaypointLocations class itself static, not just the waypoint members? Also, woyuls strongly recommend an array of transforms rather than individually named waypoint1, waypoint2 etc.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

transform.position any suggestions? 2 Answers

transform.position.x brings up error 1 Answer

Linecast blocked by colliders not actually in the way? 0 Answers

Newbie question 2d positioning and moving 2 Answers

Object Boundaries C# help please 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