Jump to content

Rick's Blog

  • entries
    65
  • comments
    96
  • views
    26,160

Component prefabs


Rick

3,808 views

 Share

So I was able to get prefabs working with the component design. It's really easy too! A prefab is just an xml file that describes the different components and their attributes that make a game object.

 

For example, in the editor I added an empty game object to my scene, then attached a spotlight component to it. This provides spotlight functionality. It creates an LE spotlight and exposes some attributes to control the spotlight. I then right click the game object and choose Save As Prefab. I provide it a name (SpotLight) and it saves an xml file named SpotLight which has the components required for that game object and saves the attributes that were set. Now when I go to add a game object I have another menu option named Prefabs, which lists all available prefabs. SpotLight shows up! I select it and it adds a game object to the scene and automatically attaches the spotlight component to it and sets the default settings. It's that easy. Distribute your prefab xml file and any component dll's that depend on it and people can add your game objects to their scene with a click of a button.

 

The editor will also validate if a dependent component is missing or not and inform you of the missing component.

 

This is getting exciting ;)

 

More to come!

 Share

11 Comments


Recommended Comments

That seems reasonable. It's almost possible to get it to work in the current editor by having an entity load an SBX and parent it to that object. But it doesn't work in code, tends to crash.

 

Leadwerks is in desperate need of some near game-ready tools, prefabs, greater control over painting. Things that both SDKers and drag-n-droppers can use. Something that can build and assemble joints for testing.

 

Good stuff.

Link to comment
Leadwerks is in desperate need of some near game-ready tools, prefabs, greater control over painting. Things that both SDKers and drag-n-droppers can use.

+1.

 

Wait +2.

Link to comment

Not so much per entity, but per bahavior. One could also have multiple behavior classes in 1 dll if they wanted to maybe make a package of behaviors.

Link to comment

This is just... what can I say?

 

+9001

 

So in other words. You could have a controller component, a sound archives compononent, and animation component, a mesh/model component, a special collision/physics component, and then save these all as a single prefab called, BasicCharacterComponent?

 

Is that how it works?

 

Then you drag drop the prefab into your scene and just edit the parameters of each component in order to define your entity?

Link to comment

>Is that how it works?

 

Since Rick isn't around I'll answer.

 

Yes and many more components than you mention. The idea is each entity has a list of components and it iterates through them one at a time, during its update cycle.

Link to comment

@Pancakes, yep. The way you would make a basic character game object is by starting with an empty game object. Then add all those components. Then you right click that basic game object and click "Make Prefab", and from now on you can add your "Basic Character Game Object" by just a menu option of Make Prefab->Basic Character (if that's what you named it).

 

Then you drag drop the prefab into your scene and just edit the parameters of each component in order to define your entity?

 

I also introduce global game objects, so not everything has to be part of a scene. One of the issues with LE's editor is that everything is at the scene level. Most every game has global (non scene) level objects as well. For example the player object would most likely be across scenes, so instead of having to add the player object in every scene and worrying about what they had in their inventory and such things, you just make the player object a global game object, and now it'll maintain all it's data between scenes.

 

A component would then be created that could set the position of the player game object and that's what would be added to each scene and on it's OnInitialize() event it would set the player's position to where you want it for that scene, but the player object would be the same as it was last scene so you don't have to worry about inventory items they had or any other data between scenes. Nice and simple.

 

 

My first test scene/situation that I'm making is a global player object that has a controller component, fpscamera component, & health component. A scene that has a trigger component attached to a game object named death_trigger (will create a physics body). I'll set this trigger attribute of what it cares about to fire it's events to the player. Then assign the OnEnter event to link to the players health component's Kill() method, which will set it's health attribute to 0. Then link the players health component even OnDead to the fpsCamera component's Dead() function which will fall the camera to the ground and tip it sideways. Will also link OnDead to the controllers Disable() method so the player can't move anymore, and link OnDead to a timer component, which will set a chain of restarting the scene. This shows that one event can be linked to many different methods to create a complex interaction of events.

 

I'm excited :)

Link to comment

or the camera itself could be an object with it's own set of specialized components... OR there can be a director object which accepts every camera in the scene as a component this way you can save several camera presets or have cameras for cinematics set up but you'll only have to connect the player object to the director as opposed to having several different camera components connected to a single player object... Or!

 

lol there are so many ways of setting it up good luck man :)

Link to comment

This is awsome Rick, seriously, if I was only an artist, I would definetely be using this tool to make my games. But when your done with it I will definetely test it out, I know it will become useful in my workflow.

 

Keep up the amazing work RIck.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...