Templates feature in r286

2 favourites
From the Asset Store
Fruit Slicer Template & Quality fruit and slice graphics (c3p,png,illustrator files)
  • useful

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • How will this new feature interract with Families ?

  • LetTheMiceFree

    Right now they are independent features.

    If an instance is set to be a template, even if it is on a family with other object types, it will only affect other instances of the same object type.

    We went with just working with instances of the same type to simplify the initial implementation.

    Maybe this can be added in the future if more people think it's useful.

  • Adding or removing children from a template will not be reflected on the replicas. This could be added in the future.

    Please add this. This would be perfect if replicas also replicate hierarchies, because then we'd finally have prefabs. This would be such a massive improvement!

    EDIT: I just noticed that this is already sort of available at runtime by being able to specify the template when creating an object.

  • WackyToaster That note was for the editor only. I meant that in the editor, adding or removing children from a template will not be reflected in the corresponding replicas. I'll update the original post to make it clearer.

  • Are instance variables already correctly linked? It states that

    an instance that has been set to be the source of property values for other instances to use. These include, common instance properties, plugin properties, instance variables, behaviour properties and effect parameters.

    But it does not seem to be the case. Am I missing something?

    EDIT: Oh yeah I absolutely broke something there but I'm not certain how yet. I have replicas that have no instance variables linked, some that have 1 of them linked and 1 not linked. I'll see if I can figure it out. :V

    EDIT2: Oh yeah nvm it does not (yet) work with families, however, this does not explain how I managed to have 1 linked regardless and 1 not linked. And on a different instance none of them are linked. Resetting the replica to (none) and back does not change this in either way.

    EDIT3: Found out how I broke it :)

  • DiegoM I discovered that when you try to create an instance with a non-existing template name, the default instance is created. I think the correct behavior here would be not create anything - similar to how nothing is created if you specify a non-existing layer name.

  • I think falling back to the default instance is reasonable if the given template does not exist. Construct's design tends to be forgiving and try to do the right thing anyway even if invalid parameters are specified. Simply not doing something can itself be confusing, and end up in bug reports like "why isn't anything created?", and cause refactoring problems like if you delete/rename a template, then suddenly no objects are being created any more, which could well be worse than falling back to default parameters.

    Even with layers, IIRC if you specify a layer number instead of a layer name, it will clamp the number to the available layers and always create an instance. It's only if you specify a name and the name doesn't exist that it finally gives up as there isn't anything else reasonable it can do.

    I think a better approach might be some kind of warning if you specify a template that doesn't exist. That could apply to an invalid layer name too (although that is harder to verify as it depends on the associated layout, which depends on event sheet includes).

  • I think falling back to the default instance is reasonable if the given template does not exist.

    Template name will often be generated from some expression and I would prefer if nothing is created when such template doesn't exist. In many cases this will be less harmful than creating the wrong default instance. Here is an example:

    Maybe as an alternative solution you could add some method to check if a template with the given name exists? Say, a System condition. And also an expression to get the template name of the created instance? (so that I could immediately destroy it if it's wrong)

  • Posted an idea on the Suggestions platform:

    construct3-21h2.ideas.aha.io/ideas/C321H2-I-283

  • While I agree with the fact that it should probably be added as an action, if you need this for any reason, know that it's fairly easy to do in JS.

    let templatePerObjectClassMap = c3_runtimeInterface._localRuntime._templateManager._templateDataMap;
    for (let templatePerObjectClass of templatePerObjectClassMap.entries()) {
     let typeIndex = templatePerObjectClass[0];
     let objectClass = c3_runtimeInterface._localRuntime._allObjectClasses[typeIndex];
     let templateMap = templatePerObjectClass[1];
     for (let template of templateMap.entries()) {
     let name = template[0];
     let data = template[1];
     }
    }
    

    if you know the object you wanna check (which you most likely do) you can get its object class using

    	let myObjectClass = c3_runtimeInterface._localRuntime.GetInstanceByUID(uid)._objectType
    

    you can now check if the template name exists by doing something like

    function templateNameExists (objectClass, name) {
     let templatePerObjectClassMap = c3_runtimeInterface._localRuntime._templateManager._templateDataMap;
     return templatePerObjectClassMap.has(objectClass.GetIndex()) && templatePerObjectClassMap.get(objectClass.GetIndex()).has(name)
    }
    
  • That code uses undocumented internals of the runtime. Do not do that! It can and will break at any time and we will not provide any support either.

  • Hi I was trying the example template, but I notice a difference in the project compared to the photo above, on "create object" there is the Template Name item, and there is no drop-down menu to choose the name of the template, but you have to write it down, if I leave it empty, the created instance automatically becomes a replica, am I missing something?

  • UltraLion

    The screenshots are from an earlier implementation, it was later changed to accepted a string rather than the fixed drop down to make it more flexible at runtime.

    If nothing, or a template name that doesn't exist, is specified, the Create Object action will just create an arbitrary instance.

  • Arbitrary means it's not a replica, right? When I open the example, by default there are only the quotes, without the name Test_Template_1 but when the instance is created it is pixellated and with the characteristics of the Pig Template. If I write a random word like cat, it continues to create an instance with the characteristics of the template, it changes only if I set "Test_Template_2" then it takes the characteristics of the pig on the top right.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)