0

I am defining an extra property for all objects like this:

bpy.types.Object.alpha = bpy.props.FloatProperty(
    default=100.0,
    min=0.0,
    max=100.0
)

However, when adding new objects, they start with their alpha at 0.0:

Alpha of new object is 0.0

Making matters even more confusing, right-clicking the property and selecting 'reset to default' correctly sets the value to 100.0:

Alpha is set to the expected default of 100.0

How can I ensure that new objects correctly start with this default value?

  • If you have a getter / setter set up on property with issue post code in question. As it stands now the question / answer do not correlate. The default value of simple property defined via code above will be correct. Related https://blender.stackexchange.com/questions/126458/internal-get-set-function-of-property ... as shown can use return self.get("alpha", DEFAULT) – batFINGER Jun 12 '21 at 05:09

1 Answers1

0

Turns out it was a problem with the getter I defined:

def get_alpha(self):
    return self["alpha"] * 100.0

should be

def get_alpha(self):
    if "alpha" not in self:
        return 100.0
    return self["alpha"] * 100.0