0
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ 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 blender.stackexchange.com/questions/126458/… ... as shown can use return self.get("alpha", DEFAULT) $\endgroup$
    – batFINGER
    Jun 12 at 5:09
0
$\begingroup$

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
$\endgroup$
1
  • $\begingroup$ could be, not should be $\endgroup$
    – batFINGER
    Jun 12 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.