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 Clw · Aug 11, 2013 at 12:53 AM · textureresources

Assets aren't found at runtime

I have this method :

 void setTexture(string pngName){
         transform.renderer.material = (Material)Resources.Load ("GeneralBuildingMaterial");
         Texture myTexture =(Texture) Resources.LoadAssetAtPath("Assets/Misc/Images/"+pngName+".png", typeof(Texture));
         transform.renderer.material.mainTexture = myTexture;    
 }

It works perfectly inside of Unity, but if i want to build and run( .exe or in the webplayer), things that would normally use those assets become white. Do you guys happen to have encountered this error? Thanks a lot for taking your time to help me!

EDIT : Materials that don't have textures that change over time don't encounter this issue, only the objects that use this material for which I change the texture every now and then.

EDIT : I usually export in the main folder of the project, is there a particular place where you have to export?

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

1 Reply

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

Answer by DaveA · Aug 11, 2013 at 01:03 AM

I always make a Build folder at the same level as Assets, and build into there.

Can't you put your PNG's into the Resources folder? Then you don't need to prepend a path. Because that's how Resources works: it loads from the Resources folder. If you want to load as you do here, you may instead want to use WWW and a file:// path, but that will be relative to a) Assets in the Editor, or b) the program_Data folder when built (runtime). And the PNG's don't auto-copy to your build _Data folder either. For that I use a script like this (put into Editor folder):

 using UnityEngine;
 using UnityEditor;
 using UnityEditor.Callbacks;
 
 using System;
 using System.IO;
 using System.Collections.Generic;
     
 public static class PostBuild
 {
 [PostProcessBuild]
     static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
     {
         string path = Path.GetDirectoryName (pathToBuiltProject);
         string exe = Path.GetFileNameWithoutExtension (pathToBuiltProject);
         FileUtil.CopyFileOrDirectory ("Assets/Textures/colors.png", path+"/"+exe+"_Data/colors.png");
     }
 }
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 Clw · Aug 11, 2013 at 09:42 AM 0
Share

Hello !Thanks for your answer. If you just use Resources.Load can you still make folders inside the Resources folder, loading some of them like this Resource.Load("Images\myImage.png")? Or all of them have to be Resource.Load("myImage.png"), having to have a mess containing all your files?

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

15 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

Related Questions

into which folder can i import my jpeg files so i can put some texture on a wall obj? 0 Answers

ridiculous load time using Resources.Load() on android build 0 Answers

Set texture / EnableKeyword not working in build 1 Answer

Resources folder fails to load 2048 texture in standalone 0 Answers

Resources.Load(path+name) as texture == null reference 7 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