playMaker

Author Topic: Create material Action.[SOLVED]  (Read 4035 times)

ttham

  • Playmaker Newbie
  • *
  • Posts: 14
Create material Action.[SOLVED]
« on: February 08, 2017, 07:29:11 AM »
Good day. Can someone please make an action that creates standard unity 5 material?
I found some code here http://answers.unity3d.com/questions/21457/is-it-possible-to-create-a-material-asset-from-a-s.html

But I don't really know how to use it.
« Last Edit: April 27, 2017, 03:51:32 AM by jeanfabre »

ttham

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Create material Action.
« Reply #1 on: February 09, 2017, 09:35:13 AM »
Here ya go mate
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 ();
}
}
}

ttham

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Create material Action.
« Reply #2 on: February 09, 2017, 09:35:35 AM »
Thanks dude  ;)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Create material Action.
« Reply #3 on: February 10, 2017, 02:40:51 AM »
:)

 I am glad you could solve this, also, I would expand on this and expose the shader name as a public FsmString so that the action can createa new material with any shaders.

 Bye,

 Jean

psypol

  • Playmaker Newbie
  • *
  • Posts: 39
Re: Create material Action.
« Reply #4 on: April 26, 2017, 06:00:46 PM »
Here ya go mate
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 ();
}
}
}

Hello.
can i have more infos about the usage of this piece of code ?
it doesn't seem to create any new material inside the project folders.
do i use it properly ?
what am i supposed to put inside the "add material" variable of the action ?
am i supposed to tell the action which material i would like to make a COPY of ?

please help

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Create material Action.
« Reply #5 on: April 27, 2017, 03:51:17 AM »
Hi,

Ok, this action isn't really working as is, I have created one on the Ecosystem.



and basically, you need to fill the shader you want, to get the list, simply try to create a material manually and check what's available in the list of shaders.

 Bye,

 Jean


psypol

  • Playmaker Newbie
  • *
  • Posts: 39
Re: Create material Action.[SOLVED]
« Reply #6 on: May 02, 2017, 03:29:30 PM »
thanks a lot jean.
it seems to do what i wanted.

For noobs like me : take note that the material(or shader actually) that is created during runtime don't appears in the hierarchy of the project.
But if you store this new material in a variable and set it on an object it will actually work and you can modify the color of it individually, independantly from any other instance of the same object.