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 anilgautam · Dec 05, 2012 at 09:48 AM · lightinglightmappinglightmaps

Access use lightmap property using script

Is there a way to access use Lightmap Property of lightmaps in unity 3d using script?

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 liszto · Dec 05, 2012 at 12:08 PM 0
Share

In a runtime script or an editor script ? Cause at runtime you can't do this there are only editor properties of Unity.

avatar image anilgautam · Dec 05, 2012 at 12:10 PM 0
Share

LightmapData lmData = new LightmapData();

lmData.lightmapFar = UnityEngine.Resources.Load("C:/Users/a/Documents/New Unity Project 3/Assets/lightmapping scene df/LightmapFar-1", Texture2D) as Texture2D;

I am trying to use this but it is showing error

avatar image liszto · Dec 05, 2012 at 12:23 PM 0
Share

Look my answer in this topic : http://answers.unity3d.com/questions/49135/how-i-can-change-lightmaps-at-runtime.html#answer-359345

2 Replies

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

Answer by liszto · Dec 05, 2012 at 12:33 PM

The lightmapData array is an array define in Unity you need to use it if you used my method. After you can do something like this :

 LightmapData[] lightmapData = new LightmapData[2];
 for(int i = 0 ; i < 2 ; i++ )
     lightmapData[i] = new LightmapData();
 
 for( int i = 0 ; i < 2 ; i++ )
 {
     lightmapData[i].lightmapFar = Resources.Load( "LightmapsCZC/" + trackName + "/LightmapFar-" + i.ToString(), typeof(Texture2D)) as Texture2D;
     //lightmapData[i].lightmapNear = Resources.Load(trackName + "/LightmapNear-" + i.ToString(), typeof(Texture2D)) as Texture2D;
 }

Resources.Load must used a path which starts in the Assets folder. With this method your code can work on multiple computer and not only on yours.

So don't use this :

Blockquote"C:/Users/a/Documents/New Unity Project 3/Assets/lightmapping scene df/"

But

"lightmapping scene df/"

Then use a naming convention as I used in my example. If I need to change my lightmaps I just used my level name and I search the lightmaps in the folder with this name in my resources folder. I must do this cause all the game is displayed in only one scene for me so I need to know which level is loaded to displayed the correct lightmap.

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 anilgautam · Dec 05, 2012 at 12:35 PM 0
Share

Thank you very much. I will try it and get back to you soon.

avatar image anilgautam · Dec 05, 2012 at 12:39 PM 0
Share

i am making a dummy project just to get the idea on how to use the switching of lighmapping to use in my actual game project. so there is no loading of levels in this one. and please tell me what is this "trackName"...???

avatar image liszto · Dec 05, 2012 at 01:00 PM 0
Share

The trackName is a prefab name and this prefab contains all my level informations/assets.

But for you, if you just have 1 scene, you can just do this :

Resources.Load( "YourLightmapFolder/LightmapFar-" + i.ToString(), typeof(Texture2D)) as Texture2D;

And in my case, I just use Single lightmap not dual, this is why I comment the second line with the LightmapNear field.

Edit : A little script for you : http://pastebin.com/23FdBnRU

avatar image anilgautam · Dec 06, 2012 at 05:31 AM 0
Share

Thanks liszto I tried this but the current lightmap disappears but the lightmap in the folder does not apply on my plane. Here is my code

void Start () { InitLightmaps(); }

private void InitLightmaps( ) { LightmapData[] lightmapData = new LightmapData[2]; for(int i = 0 ; i < 2 ; i++ ) lightmapData[i] = new LightmapData(); for( int i = 0 ; i < 2 ; i++ ) { Debug.Log("scene12/LightmapFar-" + i.ToString() ); lightmapData[i].lightmapFar = Resources.Load( "scene12/LightmapFar-" + i.ToString(), typeof(Texture2D)) as Texture2D; } LightmapSettings.lightmaps = lightmapData; }

avatar image anilgautam · Dec 06, 2012 at 06:07 AM 0
Share

Hello liszto I still not able to do this . $$anonymous$$y exact requirement is I want a code that somehow disable or hide the lightmap for few seconds after that it will be applied back. I have a terrain full of trees. I have generated a lightmap in 5 $$anonymous$$utes for an ios game. But I need some script that can cancel lightmap for few seconds and after then again enable the light map. Need Help Urgently

Show more comments
avatar image
0

Answer by liszto · Dec 06, 2012 at 07:39 AM

So first of all, move your folder from "Assets" to "Resources".

When this is done, your script must work better :).

Then, if you want disable lightmap during a short period, you can for example do something like this :

http://pastebin.com/GayDUvQU

Comment
Add comment · Show 4 · 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 anilgautam · Dec 06, 2012 at 07:50 AM 0
Share

i am sending you my simple project where I am trying to implement this but its not working . Please download it and Check where I am doing wrong. http://www.fileconvoy.com/dfl.php?id=g5afac46c9229e952999178090a1353bc08ec060fc

Please Open Scene 1 and Script nbh.cs

avatar image anilgautam · Dec 06, 2012 at 09:16 AM 0
Share

So accourding to you . We have to replace our lightmap if we want to disable it. So If our terrain is large in size and its Lightmap is arround 50 mb so This process will take a lot of time to switch lightmap. So is there any way so that we can just turn the lightmap on/off.

avatar image liszto · Dec 06, 2012 at 09:38 AM 0
Share

I answer you at 1.00pm CET+2 I'm at the offices right now. But I promise I check this ;)

avatar image liszto · Dec 06, 2012 at 06:40 PM 0
Share

I can't grab your file :/. It seems not be on the server :(

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

10 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

Related Questions

Lightmapping AND real time shadows/lights? 1 Answer

Weird Artifacts in my game lightmaps 1 Answer

Progressive light mapping is acting funky and making my models eyes too bright in certain scenarios 1 Answer

Baked Lightmaps never finish baking in Unity - what is a minimum "test bake" light setting? 0 Answers

Can't edit lightmaps. 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