GDquest has started a new kickstarter campaign to create a professional tutorial for Godot, focused on 2d games.
"Learn to create 2d games with the award-winning, Open Source engine Godot 3. Free daily tutorials on Youtube during the campaign!" "You will learn to create your own top-down game inspired by Zelda"

Code for change emissive color?

bethleembethleem Posts: 5Member
in 3D

I´m more an artist than a coder, but I have managed to use tools as AGK quite well. Godot is giving me a terrible headache for the lack of examples to learn from.

Now, I have a model a of a bulb light and made it emissive with the editor GUI. It glows green now even when a shadow comes over it. So far, so good. If I want to change it to glows red through code and not just creating another ball whit a red emissive color, how would I do that? I´ve reading the docs but didn´t find a function to get or set the emissive color in a fixed material.

Sorry if it´s a dumb question but I´m completely lost over it.


  • MegalomaniakMegalomaniak Posts: 268Member
    edited May 10 Answer ✓

    What you are looking for are likely get_parameter and set_parameter in FixedMaterial.

    And the same basically applies for ShaderMaterial as well(edit: set_shader_param), IIRC I might have posted an example file for ShaderMaterial back when there was a previous forum software installed here so it might be gone now.

    Also I don't know what AGK is so that doesn't tell me anything, after a quick google I'm guessing you meant AppGameKit though.

  • bethleembethleem Posts: 5Member

    Yep, AGK stands for AppGameKit.
    Thanks, those are the functions I need. :)
    Now I only have to figure out how to reach the material in the mesh. So easy if the docs would have any example, and so criptic the way it is. I think it´s one of the reasons why people don´t get to use godot.

  • MegalomaniakMegalomaniak Posts: 268Member
    edited May 13 Answer ✓

    script attached to a MeshInstance node:

    extends MeshInstance
    export(Color) var new_color = Color(1, 1, 1, 1)
    func _ready():
        self.get_mesh().surface_get_material(0).set_parameter(3, new_color)

    And the material is attached to the mesh referenced, not the MeshInstance node.

  • bethleembethleem Posts: 5Member

    I tried your code and it only returns "Attempt to call function 'set_parameter' in base 'null instance' on a null instance.", so the material its not really accessed.
    It´s the same message I got on every attempt I made, and I have tried a few.
    I´m about to throw godot away for good. :_(

  • MegalomaniakMegalomaniak Posts: 268Member
    edited May 19

    Can you share your scene/example file?

    Sounds like you aren't dealing with a mesh instance, so need to get the correct node to access/set the parameter.

Sign In or Register to comment.