Choose which layout new instances are created from

Get help using Construct 2

Post » Mon Oct 28, 2013 3:59 pm

Hi all,

I have a layout called 'Placeholder' where I stash assets with default values for when they're created dynamically ingame.

My problem occurs when I copy that asset into a layout and change the default values. Now ingame the default values have changed from the one in the 'Placeholder' layout.

What is the criteria to which Construct 2 chooses a lyout to create an asset from?
Moderator
B
72
S
14
G
11
Posts: 900
Reputation: 11,930

Post » Tue Oct 29, 2013 11:58 am

I would keep the default stats in the placeholder layout (if they are kinda important to the gameplay) and then set any stats on start of the other layouts. As far as I can tell if you update stats or add behaviours to a copied version it will update it for all instances.
B
46
S
16
G
79
Posts: 2,170
Reputation: 46,857

Post » Tue Oct 29, 2013 12:29 pm

As far as I can tell when creating an object at runtime the first instance you inserted at edit time is used to the object's created state. It can be a problem to find that instance unless you put it on an asset layout first. I usually just manually set the object state manually when creating at runtime though and completely disregard the edit time values.   It would be useful if there was a way at edit time to pick the initial object or even make a certain instance the reference for default values.
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999

Post » Tue Oct 29, 2013 12:53 pm

@R0J0hound Thanks for the clarification.

[QUOTE=R0J0hound] It would be useful if there was a way at edit time to pick the initial object or even make a certain instance the reference for default values.[/QUOTE]

Indeed, that would fix my issue :)
Moderator
B
72
S
14
G
11
Posts: 900
Reputation: 11,930

Post » Tue Oct 29, 2013 6:10 pm

The most sensible thing to do IMO is to create an object then immediately set all its properties with actions. I don't see any reason for the engine to pick one template instance over another, unless we implement a special "prototype" instance.
Scirra Founder
B
398
S
236
G
88
Posts: 24,428
Reputation: 194,625

Post » Tue Oct 29, 2013 10:29 pm

@Ashley this makes sense, and I agree for most situations.

My use case is having a text object with a standard text size that is used throughout the game. This means when I dynamically create any text in game it matches the predefined size, rather than setting parameters for every created instance.

There are a number of alternative solutions though, with global variables or functions to solve the problem too.thehen2013-10-29 22:30:05
Moderator
B
72
S
14
G
11
Posts: 900
Reputation: 11,930


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 47 guests