Jump to content

Entities management :


YouGroove
 Share

Recommended Posts

I'm very new to the engine , and i'm asking very basic questions that i really need for future devs !

For example i've made a level in the editor with terrain , assets and entities like different NPCs in a village.

 

My question is how to attach some actions and AI to the entities specifically ?

For example i have some simple AI and dialog code in a Class1 for NPC 1 , and i had another class 2 for NPC 2.

How can i specify in the editor for NPC 1 to use Class 1 and NPC 2 class 2 ?

It is possible to do that in the editor by specifying C++ code for a selected NPC ? Or do i have to use scripting in Lua in the editor for that ?

 

I know there is another solution , by coding directly a main loop in C++ that loads the world , but after that how to do in the program to call a class and method 1 for NPC 1 and a class 2 for NPC 2 ?

And it is possible to to get entities Ids and Names that are in the loaded level to attach classes ?

Stop toying and make games

Link to comment
Share on other sites

You can get a model in C++ with FindChild(scene,"name");

Then you just write whatever classes and AI you want and use that model handle where you need to move it, or do something else with it.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

What I normally do is add keys to the model in the editor. When I use C# I actually make the value of these keys be class names that I want this model to create and assign itself to one of it's properties. For one of my demo's I created a class called Bohan which was a boss in an RPG type game. In the Lua scripts I created keys for ClassType which I then assigned Bohan.

 

After the scene gets loaded I loop through all children of the scene entity and look for the key called ClassType and when I found one I would use reflection to create an instance of that class and pass the entity that had that key to the ctor. This was a little more involved but in C++ you can just do a switch statement.

 

I found this to work out really well actually and when using C# it gave me some pretty cool options using reflection and doing it this way as I "could" make Bohan a separate DLL and make changes to how that boss works without touching the main game project.

Link to comment
Share on other sites

Thanks guys !

I choose C++, so i plan to call some function like FindChild, but instead FindAllChilds !

Or perhaps use a file describing all name entities in a level than call the GetChild, and when found instantiate in an Array or Hashmap

this class for this entitie.

Each instance class will have it's own parameters going on : Life, mana, States AI etc ...

 

For C# , does it cover actually all engine stuff in latest version in the majority like 90% compared to C++ that covers all functions ?

Perhaps i could try tonight C# instead of C++ and CodeBlocks why not ?

Stop toying and make games

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   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.

 Share

×
×
  • Create New...