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 kingrex · Apr 26, 2011 at 08:18 AM · texturestatic

how to define a static texture2D?

i want to assign a picture from a folder in my computer to a texture2d, but not in the inspector! i want to do it in script. but it gives me an error like this:

"NullReferenceException: Object reference not set to an instance of an object"

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Cyb3rManiak · Apr 26, 2011 at 08:26 AM

You can use Resources.Load or asset bundles to load textures on the fly without referencing them first. Just make sure to read the docs for its' limitations, especially if you're developing a streamed web player.

Comment
Add comment · Show 5 · 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 kingrex · Apr 27, 2011 at 04:46 AM 0
Share

but looks like this is just for editor mode! how if I want to do this when the game is built? then I won't have any folder called asset :(

avatar image Cyb3rManiak · Apr 27, 2011 at 09:25 AM 0
Share

This is NOT for editor mode... The idea is that you create a folders called Resources somewhere inside your asset folder. Put anything that you want to load dynamically in those folders. At runtime call var myTexture: Texture2D = Resources.Load("$$anonymous$$yAssetToLoad"). The down side is that because Unity doesn't know which of the assets you want to load at compilation time - when the time comes (By default when the application starts) it will add ALL of the assets that are in folders called Resources to your build, so that it can use them on demand, and they will also take up runtime memory.

avatar image kingrex · Apr 27, 2011 at 04:50 PM 0
Share

thanx for the help bro

avatar image Cyb3rManiak · Apr 28, 2011 at 03:05 PM 0
Share

No probs dude :)

avatar image kingrex · Apr 30, 2011 at 08:29 AM 0
Share

sorry I built the game but there was no folder called Resources! how should the user put some extra images in that folder? only I can put images in the folder before building the game, but end user can't.

avatar image
0

Answer by Cyb3rManiak · May 01, 2011 at 08:46 AM

The Resources folder isn't exposed to the end user. It's used by you, and you alone when you develop your application. If you want your end user to add/change assets, you'll need to use other tools, such as the WWW class with the file:// syntax or the System.IO namespace of Mono (like this, for example). There are plenty of examples for it in the forum, and maybe even in the WIKI. Try searching for System.IO for example.

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 kingrex · May 01, 2011 at 09:35 AM 0
Share

thanx bro I'll search again

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

No one has followed this question yet.

Related Questions

How to make a plane with a texture flicker, as if it was animated? 1 Answer

Assigning UV Map to model at runtime 0 Answers

Texture in GUI 0 Answers

How do I map a texture to a primitive instance? 4 Answers

Global Variables Refuse to Cooperate 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