- Home /
Loading terrainData from Resources into existing Terrain object using UnityScript
I want to load different terrainData assets from the Resources folder at runtime. The following doesn't work in Unity 3.0f5. I'm clearly misunderstanding something about the relationship between a Terrain script/object and the terrainData.
var pathString : String;
var newTerrainData : TerrainData = Terrain.activeTerrain.terrainData;
newTerrainData = UnityEngine.Resources.Load(pathString, TerrainData) as TerrainData;
Terrain.activeTerrain.Flush();
Answer by zharramadar · Jan 19, 2011 at 03:11 PM
Don't you need to assign back the terrainData object to the terrain? I mean, after: newTerrainData = UnityEngine.Resources.Load(pathString, TerrainData) as TerrainData; You need to do: Terrain.activeTerrain.terrainData = newTerrainData As the terrainData object you placed in the newTerrainData is not a pointer to the terrainData in your activeTerrain, but it is a copy of it. In fact, you can disregard the line 2 and skip directly to line 3
Your answer
Follow this Question
Related Questions
"Terrain.activeTerrain" what does it do? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to generate random terrain like platforms for a 2.5D game. 0 Answers
Randomizing tile textures 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers