Constrain Attribute - My Friend, My Arch Enemy

RattleheadRattlehead Member Posts: 485
edited November -1 in Working with GS (Mac)
Dear GameSalad,

RE: Constrain Attribute Behavious

Oh, how I love you... you make it easy to continually update values without much effort. Happily populating global variables that make the various cogs of my game go 'round.

Oh, how much I hate you... while easy and without complaint, you also choose to drive the performance of my game six feet under with no mercy and bring those same cogs you so lovingly are a part of to a halt.

*sigh*

I know this has been discussed many, many times before but I am still struggling to understand what is (really) going on under the hood in parts of the GameSalad toolset. If you look at the description for this behaviour in the help section, it really doesn't amount to much.

All I want to understand is what it is really doing...

What is causing it to crater the performance once it is on the device?

Are there guidelines for how many constrains should be running at any given time?

Are there alternate methodologies to my friend/enemy Constrain Attribute that can be used?

Are there ways to optimize a game heavily laden with Constrain Attribute?

Are there plans to look at ways at optimizing it under the hood?

If I were to compare it to what I would do coding it by hand, I can't see it doing more than variable assignments (=) on every clock cycle. But there has to be more... Is GS storing them in something funky like a hash table or dictionary which is cratering performance through read/writes?

ARGH!

It just seems every time I get a game almost to completion, things like Constrain Attribute - which seems sooooo freaking useful - put my plans on hold or force me to work on something with reduced logic or scrap it altogether.

If someone from the GS team could shed some light on this topic, perhaps one day I can reconcile with my (sometime) friend Constrain Attribute...

Sincerely yours,

Devastated-in-Calgary

Comments

  • ORBZORBZ Member Posts: 1,304
    A constraint is an event dispatch. Every time the value of the constraint's source changes it dispatches an event to update the target variable.

    They are not as good as Change Attribute which is basically assignment as it does no monitoring of the right hand side of the equation.

    I get very good performance out of Constraints because I am very careful to put simple and not frequently updating values in the constraint's source. If you have a very complex equation it's better to do the whole equation in one expression than to break it down into multiple constraints each assigning to a temporary variable.

    Put a rule around constraints that determines when they need to fire so that they don't fire constantly.
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    You guys will will be more likely to know than me (new GS user), but using the game.time or self.time seems to be much better better for performance? And then using whatever equation you prefer to constantly flick an attribute between 1 and 0 with a rule that performs an action on the 1.

    At the moment I'm liking: When 0 (an attribute i make) = (self.time*20)%2.... do stuff.

    Higher multiples of the self.time for more constant attribute changes of course.

    It doesn't work great for smooth character movement but for other stuff it's useful.
  • cbtcbt Member Posts: 644
    And then ORBZ was here...

    :)
  • RattleheadRattlehead Member Posts: 485
    Thanks guys! ORBZ... I think I'll go back and start looking at ways of trimming out some logic. It doesn't seem that brutal but then again, maybe I need to put it down for a day and come back and see if I can't refactor the entire deal rather than try and patch work it together.
Sign In or Register to comment.