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
2
Question by David 3 · Apr 07, 2010 at 10:45 AM · textureloading

Load Texture at Run time from file

Hi,

The below code will load a texture from the resources - how would i load C:\test\tex.png ?

function Start () {
  var go = new GameObject.CreatePrimitive(PrimitiveType.Plane); 
  go.renderer.material.mainTexture = Resources.Load("glass");
}

There does not seem to be a load method accepting system paths :( [can i cheat this with mono?]

David

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 yoyo · Apr 25, 2010 at 06:40 PM 1
Share

You can't use system paths from Resources.Load, but you can have folders beneath your resources folder, e.g. Resources/test/tex.png could be loaded with Resources.Load("test/tex"). Not exactly what you're asking, but might be relevant.

2 Replies

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

Answer by duck · Apr 07, 2010 at 10:47 AM

Use the WWW class, and provide a file url in the form of:

var url = "file://C:/test/tex.png";

You can then read out the www.texture value once the www request has completed. For example:

function Start () { // Start a download of the given URL var www : WWW = new WWW (url);

 // Wait for download to complete
 yield www;

 // assign texture
 renderer.material.mainTexture = www.texture; 

}

This should work in standalone builds, but won't work for webplayer builds.

If you're using C#, see this answer for more information on how to use WWW in c#.

Comment
Add comment · Show 10 · 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 David 3 · Apr 07, 2010 at 12:49 PM 0
Share

in C#

// load it www = new WWW ("file://C:/test/tex.png");
// display it renderer.material.mainTexture = www.texture;

avatar image duck ♦♦ · Apr 07, 2010 at 01:02 PM 1
Share

Added link for information about how to use WWW in c#

avatar image bcsanches · May 03, 2011 at 02:27 AM 0
Share

Is possible to make this work in webplayer builds? Even when the texture is in the server?

avatar image R-GiGgS84 · Aug 01, 2011 at 09:39 AM 0
Share

can this work on android platform?

avatar image ina · Sep 17, 2011 at 06:27 AM 0
Share

does this also work for relative file paths

Show more comments
avatar image
0

Answer by astracat111 · Feb 23, 2018 at 04:57 PM

I believe you use persistentDataPath after extacting the data into it at runtime:

 function Start () {
    // Start a download of the given URL
   var www : WWW = new WWW (Application.persistentDataPath + "filepathinPersistentData");
  // Wait for download to complete
  yield www;
  // assign texture
  renderer.material.mainTexture = www.texture; 
 }

That will work on android, might work on webgl depending on permissions, not sure about that one.

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

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

8 People are following this question.

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

Related Questions

Load a transparent texture by script 1 Answer

How can I load pre-compressed textures at run-time (without using assetBundles) 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to gradient-wise fill a bitmap programmatically 1 Answer

How would I implement this game mechanic? 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