Create an object from behavior

Is it possible to create an object from behavior
I write the action in DoStepPreEvents and nothing happens

I seek to do same thing.
In fact we can yet pass object as properties in behavior just Number, String and Boolean.
If you want create an object you should use "custom " behavior function and call the action in your events.

I wish we could choose a scene for reference in our behaviors similar to external events and layouts.
I don’t personally like to creating functions specifically to pass objects to a behavior, if you have lot of objects to work with it can quickly turn in to a pile of spaghetti.
This is the point when 4ian would probably say something like if that’s the case then our behavior is “too” complex need to simplify it and break it up in to smaller chunks but I often hit this wall with the behaviors that I do want to work with objects in a behavior, check collision, distance, animation…etc and I always end up with a pile of spaghetti. For this reason, personally I don’t use behaviors as much as I would like to. I keep prefer to organize my events in to groups and external events and maybe functions but exactly because of this limitation, I don’t personally like to work with behaviors.

1 Like

Would it be possible to use some Js to create a pointer to runtime Scene in the behavior instance and use that to create new objects?

Fun to do but It’s not a long-term solution.

Well, I got to that point, too :confused:
Making events on objects with behaviors is possible, but quite limited if the object cannot interact with others directly.

Ideally, behaviors are small enough to deal with just a single thing and could build on top of each other by re-using other behaviors.

This is somewhat tricky to get properly but I’ve created this card: Trello

If you want create an object you should use "custom " behavior function and call the action in your events.

Yes right now your only possibility is to get the objects to interact with by passing them in actions/conditions as parameters.
“Passing” an object/behavior to another behavior as a property is a bit tricky because what should get passed? A single instance of the object with the required behavior? Multiple instances? How do you select that in the UI?

If you can brainstorm on this that would be helpful to see what you think :slight_smile:

When there is an Objects parameter in a instruction a list of all instances of specified object is passed. Right?

In a function we can set “Objects” (list), i imagine same thing for behavior properties.

For get the behavior attached on each instances coming from Objects (list), i don’t remember how the engine get it, but i guess the behavior can be find with the current instance of Objects list?

And the by pass solution use Objects list. So, all instances of the object is a good choice :thinking: ?

About the engine :
In external events and layout before edit it we need choose a scene, if this is used for link the external event/layout with the scene, same link can be done between behavior/scene in background for get the objects present on scene.

I have the feeling making behaviours self contained and reusable and easy to share maybe get too much focus and we are forgetting the most important thing which is productivity.
Let’s consider for a moment I don’t want to share my behavior, I want to use them only for an object oriented approach to organise my events in to behaviors only to keep things tidy.

Let"s say I want my player to be able to shoot rockets if a certain key is pressed and I want the rockets to cause damage to walls and I want the walls to destroy if getting too much damage. It could be implement as follows using behaviors and an object oriented approach:

I would have a player behavior which would contain the events to control the player and also to create rockets at a certain point of the player when I press a certain key. In this case I need a reference to the rocket object because I want to create instances of the rocket.

Then, I would have a rocket behavior which would contain the events to move the rocket to a certain direction at a given speed and maybe I also would like to create a particle emitter and move it along with the rocket for a better visual effect. So then in the create event of the behavior I would apply the force to the rocket and create the particles emitter at a certain point of the rocket and link it with the rocket. So in this case again, I need reference to the particle emitter object because I want to create an instance of it. Then in the update event of the behavior, I would like to move the particle emitter along witht the rocket in which case I need reference to the instance that is linked to the rocket.
I also want to check collision between the rocket and wall and when the rocket collide with a wall, I want to apply some damage to the wall and Do - 10 to integrity of the wall. In this case, I need reference to the wall instance the rocket is colliding with.
Finally, on collision I would destroy the rocket the behavior attached to and the particle emitter linked to the rocket, in which case again, I need reference to the instance of the emitter linked to the colliding rocket.

Then, I would have a wall behavior which would initialise an object variable called integrity with the default value of 100. Then in the update event I would check if the value of integrity <= 0, destroy the wall.

Now, If I need to create functions and edit behavior properties to pass objects to behaviors to hook this all up and get it all working, in my opinion it is not going to be productive. Yes, we can make them reusable, self contained and even share it with others, but if I need to do staff for my self only I prefer not to mess with setting this up.

I would like to just go and do it as normal and as I mentioned, if possible, the best way to do it would be to select a scene to get reference to the objects present in the scene. It is maybe going against the whole purpose of behaviors being self contained and be able to share it, re-use it but I think it would be better for productivity and object oriented approach and to keep things tidy :+1: .

1 Like

I sure think the entire scene should be accessible (even if you cannot know what exists or not on it) and not just the object, but what is really needed is a “prefab” object that could contain other objects, a default behavior editable directly in the prefab interface, the possibility to add more behaviors and it would act as a pixi container on the scene, pretty much what you can find in UE4 or unity. They would be hell to implement, but definitely worth it.

Ah, so it’s limited in the aim to have totally portable / shareable behaviors!
I hadn’t understood. Well, it’s very regrettable and limit the all users.

Well, making content to be consumed by others is difficult and always require to take extra steps.
When you do staff for your own needs only, it can be a pain to be forced to go through those extra steps just because “it could benefit others” if you choose to share it.
I would prefer to decide if I want to share something and go through the extra steps to prepare it or I just want to get staff done the way it fit me best. Passing objects to behaviors and especially to create behavior functions to do this is not something I personally would like to deal with unless I do actually need it for my own purposes.
I mean manually, creating the properties, the functions, parameter flags, explanations, descriptions, call them, pass object one by one…etc

For my own personal needs, I would really prefer to be able to just select the scene to reference all the object and go. Could still add some ways to pass specific objects to behaviors one by one if someone really need that functionality to share behaviors.

So I think it is worth considering for a moment that what we need, how we want to do it and then we can consider how to wrap things up to be shared only if we want to. :+1:

1 Like

Basically, the functions should enable to support Objects or Objects Templates. Objects would be directly an object that would become global when you use the extension, and Object Templates would be something accessible like an Object Group from the extension and for the end user he would have to add it in the object properties of that other behaviorless object and it would automatically make sure it is the correct object type, add any predefined variable or stuff to make it conform to the standards of the extension. Then if you need for instance to add a trail you can create a extension Object (particle) and set it up how you want and if you need to integrate two objects in a behavior ypou can attach the other to the behavior through the object template.

I don’t know, it sounds a bit too complicated to me, I am a little lazy right now, I really don’t want to mess with templates, prefabs, properties, functions just to help others use my staff. I would prefer something that require no effort or very little.

How about this.
In the behavior properties, we could create “behavior objects” and set the type of the object if it a text, sprite or else and enter the name of the expected behavior attached the object.
Then, I could use this object in my behavior events as a reference, a placeholder.
Then, when I run the game and my behavior objects being initialised, it would go ahead scan the level and find the object and their instances of selected type that has the selected behavior for me and get a reference to that object automatically and initialize the behavior objects as they were the actual objects.

For example. staying with my rocket launching example. Let’s say I would have a player with a player behavior. In the player behavior I would create a “behavior object” called “RocketObject” and set it to be a sprite object and must have the behavior called “RocketBehavior”. I would type in the behavior name manually. Then when I create the rocket I would use this behavior object called RocketObject in place of the create object event.

Create object RocketObject at position X and Y

Then I would of course have a sprite object in the level with the behavior “RocketBehavior” attached to it and so when I run the game, the behavior would go and find it for me and get the reference to create and instance of this object that fit my desciption stored in RocketObject.

This way, even if a behavior would have no actual logic inside, it could be still used to flag objects in the scene to be found and referenced from within behaviors.

So the behavior can be more complex, could reference external objects while the behavior would be self contained and easy to share and require no objects and behaviors passing all over the place. We could just flag objects with behaviors in the scene and use behavior objects to find a reference to specific objects and their instances.

Does it make any sense? Would something like this be possible?

That is literally what I said

Sorry I did not understand really what you said. It did sound very complicated:

So we do agree then to do it like I have described right? If we both talking about the same thing :+1:

But it is still a question if technically is it possible.

Yes, I was proposing two things: Behavior objects (what you said) and Object Templates, which would be a way to apply certain rules to an object to assure it’s compatibility with the behavior.