How to "upgrade" an object to a family

Tags

Add to Favourites

1 Favourites
Construct 3
Construct 3

Buy Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Buy Now Construct 3 users don't see these ads

Tutorial Stats

? 88 sessions
? 2 sessions per day
? 94 page views
? 2 page views per day

Report Tutorial

Report this tutorial for spam or for being inappropriate.

Published 4 Oct, 2017
716 words
~3-5 minutes

It's always good to plan ahead when making a project, and determine when you'll need a family in advance. However it's easy to forget and end up with a large number of events using a specific object type, when you'd rather all those events were for a family instead. This tutorial will show you how you can convert all those events to refer to a family, preserving any references to instance variables or behaviors, without having to re-do all the events by hand.

An example

Suppose we have an object Monster which we want to replace with a family called Enemies so we can easily add different kinds of enemies... but we already have 100 events for Monster! Here's how to "upgrade" it to a family.

Back-up

This tutorial involves changing large parts of your project. If you make a mistake, you could end up with quite a mess. So be sure to make a backup of your project first.

The process

First of all, we need to create the family to replace with. We can't create an empty family, so in fact first we need to create an empty object which will only be used temporarily. In this case, create a new Sprite and add it to the layout (no need to worry about its image, we'll delete it later). If you're replacing a different kind of object, like a Text object or Tiled Background, create one of them instead.

Next, create the family. In this case we'll call it Enemies. When prompted to add an object to the family (since it can't be empty), add the empty object you just created and press OK.

Now we need to add all the same instance variables, behaviors and effects that the object has to the family. Objects can only be replaced with other objects or families with matching instance variables, behaviors and effects, so we need to add matching ones to the family. They must all have identical names. For example, if Monster has the number instance variables health and speed, and a bullet behavior named Bullet, we must add health and speed number instance variables to the Enemies family, as well as a Bullet behavior.

Now the events can be replaced with a reference to the family! In your event sheet, select all (Ctrl + A) then press R (for Replace Object). First choose the object you want to replace (in this case Monster), then you can choose to replace it with the new family. If the family does not appear, or a message appears saying there are no objects that it can be replaced with, double-check the family has exactly the same instance variables, behaviors and effects, all with the same names and types. If you have multiple event sheets with events referring to the object, you'll also need to repeat this process for each event sheet, selecting all the events then replacing the object with the family.

Your events now refer to the family! But the original object Monster is not in the family. We can't add it yet either, since its own instance variables and behaviors conflict with the family's.

So now delete all the instance variables, behaviors and effects from the original object. Try not to feel too nervous - by now there should be no events referring to the object at all, since we replaced them all with the family. (And you made a backup earlier... right?)

In the project bar, edit the new family and add the object to the family. In this case we'd add the Monster object to the Enemies family. If you get an error, make sure you deleted all the instance variables, behaviors and effects from the object. We also don't need the temporary object any more, so you can remove the temporary object from the family, then delete it from the project completely from the Project Bar.

End result

Now all your events refer to the family instead of the object, and the object inherits all the same instance variables, behaviors and effects from the family. So it works exactly how it used to, but you can now add other objects to the family, taking advantage of applying the family events to different object types. Hopefully this will come in handy at some point!

Share this Tutorial

Make games in your browser

You may use this tutorial for any purpose (even commercial) if you properly attribute it. Click here for more information.

Beta Mode: You may find bugs/missing content. Read more & Report Bugs