Topic: How to change the terrain texture with a PlayMaker action ?

I tried something pretty simple but... it doesn't work :-(
Please have a look to this video : https://youtu.be/85M4SXY3qGA
Best regards
Phil

Re: How to change the terrain texture with a PlayMaker action ?

Hello.

It doesn't work that way. Terrain Engine is much more complex.
Below is the action for this, but please in the future ask a question to the developer of the asset to which your question relates (in this case Playmaker).
And keep in mind that Terrain Engine will save its state after exiting play mode.

using HutongGames.PlayMaker;
using UnityEngine;

namespace Playmaker.Actions
{
    [ActionCategory("Terrain")]
    [HutongGames.PlayMaker.Tooltip("Set Terrain Layer")]
    public class SetTerrainLayer : FsmStateAction
    {
        public Terrain terrain;
        public TerrainLayer layer;
        public int layerIndex = 0;

        public override void OnEnter()
        {
            DoEnter();
            Finish();
        }

        private void DoEnter()
        {
            TerrainLayer[] layers = terrain.terrainData.terrainLayers;
            layers[layerIndex] = layer;
            terrain.terrainData.terrainLayers = layers;
            terrain.Flush();
        }
    }
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: How to change the terrain texture with a PlayMaker action ?

Hello Alex
Thanks very much for the script, it works !!!

Something that I don’t understand : if I drag a “regular” 2D texture over the Terrain Item thumbnail, it replaces the terrain texture. But with your script, I can use only a "terrain layer", not a simple texture, and this would be helpful for instance to replace a terrain for instance with a geological or a Cassini map. Do you think that there would be a way to use a “regular” texture ?

I am afraid that if I ask the PlayMaker team for a custom action concerning RWT, they will tell me the same thing : “see with the developer of the asset” ;-)

Best regards, Phil

Re: How to change the terrain texture with a PlayMaker action ?

Yes it is possible. Action below.

The fact that your terrain is made using RWT does not make any question RWT related.
In this case, it does not matter at all how the terrain is made: manually, using some tool or Unity API. It will just work.
Please do not misunderstand me: I am always ready to help if I have experience in something. But it is better to start looking for help from a person or a team, with which your question is directly related.

using HutongGames.PlayMaker;
using UnityEngine;

namespace Playmaker.Actions
{
    [ActionCategory("Terrain")]
    [HutongGames.PlayMaker.Tooltip("Set Terrain Texture")]
    public class SetTerrainTexture : FsmStateAction
    {
        public Terrain terrain;
        public Texture2D texture;
        public int layerIndex = 0;

        public override void OnEnter()
        {
            DoEnter();
            Finish();
        }

        private void DoEnter()
        {
            TerrainLayer[] layers = terrain.terrainData.terrainLayers;
            layers[layerIndex].diffuseTexture = texture;
            terrain.terrainData.terrainLayers = layers;
            terrain.Flush();
        }
    }
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: How to change the terrain texture with a PlayMaker action ?

Thanks a lot, it works well ! And really sorry for the misunderstanding, you are right, this PM Action is not related to your asset ! And of course I confirm that your are always very responsive and helpful.
Have a nice day (or night !)
Phil