TLDR: Make an action, where you pass a parameter of type variable to a local variable inside that action. Then change your Animation based on that local variable. (You need to define that Parameter somewhere in your scene)
I don’t know the official wording, so I will use: internal for anything that is inside your extension external for anything that is inside your scene (outside your extension) data for anything a parameter can hold (variable, text, color,…)
The general issue (I was having too) is, that you cannot access external data from within any CustomObject/Behavior/Function, without setting up parameters and the corresponding functions for it. It’s strictly needed for the communication between the internal and the external. I know by now, that this is by design. Otherwise, extiensions would not be universally usable for any project. You will always need to define a parameter, that can pass your external data to your extension.
So if you wanted to automate this internally inside any LifeCycle Method (as I did, and you seem to do, since your setup is inside onCreated), then I think I need to disappoint you
Now to my solution for this:
It is possible, but not inside onCreated (at least from my experimenting with this):
Make an action, where you pass a parameter of type variable to a local variable inside that action. Then change your Animation based on that local variable.
Inside your scene:
The c.Object action:
Its parameter set-up:
And please anyone, call me out if I am wrong. I would love to
(PS. to be fair, if it actually was it that way, we could start to not use the event sheet at all anymore - I gave up on that approach )
IDK if “OnCreated” is where you want your events. That function only gets called once and doesn’t accept other parameters. Plus, you can’t change any settings ahead of time because the object wouldn’t exist.
You could create an action and call it from the scene with a text parameter or I guess you could add a property and check it’s value from the doStepPostEvents function.
Using an action might be easier while adding a property would allow you to set the value from the object’s setting screen. You can also add an action and expression function to get and set the value. GD can automatically add them or you can manually create them.
I can elaborate if needed depending on which method sounds like the best way. I guess it depends on how frequently you need to use it. If it’s just once or infrequently then add an action. If you want to be able to set the value from the object or instance setting screen or monitor something on every frame then add a property.
99.99% of the time you pass the value of a variable and not the actual variable so as long as it’s a string, it doesn’t matter what type of variable it is or even if it’s a variable. It could be an object or expression. It only matters that it’s value is a string or whatever the parameter is set as.
It can be a pain to communicate with custom objects. I wish it was easier. I wish you could easily add a behavior to multiple objects and then let them communicate with each other without events from the scene. It can be done but I don’t know how. Most methods seem complex. The alternative seems to be adding functions and triggering them either on every frame or just when needed.
I don’t know the purpose of “has animation”. I think it’s only used with Javascript but I could be wrong. Either way, I don’t think it’s needed in this situation.
Yes, I use that method too, but I use it inside the functions tab. If I understood correctly, you’re telling me that I can’t use it from inside the c.object… meaning there’s no way for an internal object to read a variable (even a global one) that exists outside of it.
To explain better what I’m trying to do… I need the animation to change at creation time so that the collisions of the object’s various animations follow it in real time, avoiding stick behavior, follow‑position tricks, and similar hacks.
ive a var that has text “animation” depending on equipped item…and i would like that the c. object when created swap anim to that text
i know how to do it inside a function, but if possible i wonder if it can be done by object.
i understood the on created issue, but…do you think it can be done inside the object and not as a function?
basically at any equip swap the text change and must bbe read again
To be fair, I have not grasped fully, why you cannot setup your logic below the CreateObject action, and also, why you are not using more common logic, that doesn’t require object creation, but simple state changes that trigger your logic dynamically (show/hide, activate/deactivate behaviors, change collision box, change anim, …)
But I can tell you, that there is actually one Property, that can be changed ahead of creation and it is not bound per instance (which makes it a perfect fit for onCreation, as it enables data setup ahead of creation).
It’s the SceneProperties, which are available to Behaviors only. So you will need to add a Behavior to your Object and then handle your OnCreate from there. It works a bit different, from CustomObject, but is totally achievable. I have had errors using it myself tho…
The flipside is, that these properties cannot be changed per instance.
Wait, wait, wait… this is all too complicated… it is right there at the top of our left toolbar. I was making things complicated here
Create a variable inside your Extension (scene or global). Change your animation accordingly inside your OnCreate Lifecycle Method. And now you simply port your variable, that things depend upon inside your extension.
Are you creating the object at runtime? I’m guessing yes.
I wish there was a way to pass a parameter during creation. Sort of like switches you use in Windows.
My only thought is adding an object and then triggering an action. If you really wanted to do it with 1 action then you could create a regular function that would create the object and then trigger an action using a passed parameter.
There are behaviors that communicate with each other without any events. Think of the platform, pathfinder and even physics. They communicate simply by adding a behavior to the objects. Under the hood, they use managers which add objects to a list. I don’t understand that process.
I just don’t see any other way to communicate between objects without using functions.
As long as nobody proves me wrong… it simply isn’t possible to swap animations from the object section of an extension. If you want to try, go ahead and try changing the animation of the object(or one of its children) from the object section based on whatever event you want from your scene or by the same c.object. I believe the ‘has animation by JavaScript’ checkbox is meant exactly for this.
for swap animation i mean at runtime or dynamically…
telling you this bcs i even tried something simple like changing anim by a c.object.var without success.
now i’m trying to find this secret javascriptcode to bypass the problem…if exists
(I guess the animation checkbox is for changing animation of the whole object itself. We can only make changes to the objects children, which should be sufficient in your described case)
i was correcting myself i was saying you can do it with c.object var before your post.
but for god sake i can’t change this c.object global var by some scene event…it’s what stopping me rite now.
if it can help i don’t have any children…or better the custom object itself is the children (with some anim)
what i’ve done to make it works is to create the global inside the c.object as you said and swap the anim by said var…now as last step i need to change this var by any method from the scene.
and…i wonder in the end why i can’t just do it without such var …
Same rules as stated before: you want to tell your extension something from outside (the event sheet)? Create a parameter and a function and let them communicate. There is no way around this.
You don‘t want this? Also fine: put your whole logic inside your extension.
Yeah, I know… I’m basically following a unicorn at this point.
…and AI said the same…llol…
It just bothers me when you get right to the point where the solution is within reach, and then you’re forced to stop…
Anyway, I know … I was trying. (Keith said the same thing).
It’s just that I don’t give up easily when the evidence says otherwise.