playMaker

Author Topic: Adding temporary material to tamplate.  (Read 2625 times)

ttham

  • Playmaker Newbie
  • *
  • Posts: 14
Adding temporary material to tamplate.
« on: February 07, 2017, 07:15:22 AM »
I need to create empty material in my template on a game start to change its property's independently from other similar objects, is there a way to do that.

ttham

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Adding temporary material to tamplate.
« Reply #1 on: February 09, 2017, 08:14:31 AM »
I'ts just like 1 line of code, and there is no way to do that ?

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: Adding temporary material to tamplate.
« Reply #2 on: February 09, 2017, 09:33:58 AM »
Well, material has two constructors... Material(Shader shader) and Material(Source source).  The first one, creates a new material with a given shader and second one creates a new material with properties of a different passed in material.

I have done a simple action with the first constructor... It's attached to this post, see if it works as it's my first attempt at playmaker actions.

Make sure your shader is in Resources/Shaders

And then put the name of the shader in the "shader"

and in path put Shaders

The reason I've done this because function shader.Find only works in Editor and not in built game.

 

« Last Edit: February 09, 2017, 09:36:28 AM by elusiven »

ttham

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Adding temporary material to tamplate.
« Reply #3 on: February 09, 2017, 09:40:06 AM »
Thank you very much!

I made an action to its a bit simpler but it dose what i need to :)
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System ;


namespace HutongGames.PlayMaker.Actions

{
[ActionCategory (ActionCategory.Material)]


public class AddMaterialAction : FsmStateAction
{
[UIHint(UIHint.Variable)]
public FsmMaterial AddMaterial;


public override void Reset()

{
AddMaterial = null;

}


public override void OnEnter()

{
AddMaterial = new FsmMaterial (Shader.Find("Standart"));

Finish ();
}
}
}
« Last Edit: February 09, 2017, 09:42:11 AM by ttham »

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: Adding temporary material to tamplate.
« Reply #4 on: February 09, 2017, 09:45:18 AM »
Thank you very much!

I made an action to its a bit simpler but it dose what i need to :)
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System ;


namespace HutongGames.PlayMaker.Actions

{
[ActionCategory (ActionCategory.Material)]


public class AddMaterialAction : FsmStateAction
{
[UIHint(UIHint.Variable)]
public FsmMaterial AddMaterial;


public override void Reset()

{
AddMaterial = null;

}


public override void OnEnter()

{
AddMaterial = new FsmMaterial (Shader.Find("Standart"));

Finish ();
}
}
}


I see you have used Shader.Find - While this will work in Editor, according to docs it won't work runtime in a built game.

https://docs.unity3d.com/ScriptReference/Shader.Find.html

ttham

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Adding temporary material to tamplate.
« Reply #5 on: February 09, 2017, 11:01:04 AM »
Hm ok thank you.