Jump to content

Hard time understanding the property/component system


photo

Recommended Posts

Hi guys,

I downloaded Unigine yesterday and so far I am having a blast trying everything out. But I just can't seem to understand how exactly properties and components work. I understand the idea and structure behind it, but when I try to create a property file (by declaring it in a C++ class), it just doesn't work and I don't see any newly generated file in the editor. So my questions are:

1) Does the C++ class that inherits from ComponentBase need to be at a specific location to be recognized by the engine?

2) I followed your Pawn/Spinner/Projectile tutorial (but with my own variables) - set the property name, parameters, etc., registered it in AppSystemLogic and made sure that REGISTER_COMPONENT is implemented in my newly created class. When I build the solution and run the app, nothing happens. What did I miss?

3) More of a general question, because coming from Unity and Unreal Engine, it's a bit confusing: If I edit the code in Visual Studio and save it, is the Editor updated automatically or do I have to do anything else? It confuses me because I followed your programming documentation and when I run the app from VS it worked during my first steps, but if I run it from the SDK nothing happens. The workflow is really new for me...

Thanks for any help!

Link to comment

Okay, I managed to make the properties visible in the editor. The culprit seemed to be a wrong type in the header file which was not throwing any errors for some reason.
I'm just trying to log the value of a variable in the header file to the console within update() now (in my class), but nothing happens. Maybe someone can help? I'm sure I'm missing something obvious but I can't seem to spot it.

Link to comment

Hi Chistine,

As for your questions:

1) Does the C++ class that inherits from ComponentBase need to be at a specific location to be recognized by the engine?

No, it just should be included in your project and compiled with it. All properties for your components (if defined and registered properly) will be created in the data/ComponentSystem folder of your project.

3) More of a general question, because coming from Unity and Unreal Engine, it's a bit confusing: If I edit the code in Visual Studio and save it, is the Editor updated automatically or do I have to do anything else? It confuses me because I followed your programming documentation and when I run the app from VS it worked during my first steps, but if I run it from the SDK nothing happens. The workflow is really new for me...

The workflow is as follows:

  1. Edit your code is VS or any other IDE
  2. Compile and build your application
  3. Run your application either via VS or via the SDK Browser (see instructions below)

UnigineEditor is used to build and configure your virtual worlds, it actually does not execute your application's code written in C++. So, to check your code you should run your application (e.g. via the Run button in the SDK Browser).

Please check if the platform and configuration settings for your project in the VS (the configuration that you actually build) and the one used to run your project in the SDK Browser (the one that is actually run) match. This seems to be the reason for "when I run the app from VS it worked during my first steps, but if I run it from the SDK nothing happens"

E.g., if you have Debug x64 config in VS:

ide_project_settings.png

You can open the Projects tab of the SDK Browser, find your project and click "..." under the Run button to see Run Options.

For our example you should also have Debug, 64 bit config in the Run options set:

sdk_config.jpg

Hope this helps!

P.S. This article may be useful, it helps to understand the key concepts when migrating to UNIGINE from other engines.

Thank you!

Link to comment

Hi fox,

thank you very much for your thorough explanation! The "Debug" option in the SDK Run menu was indeed turned off and that was causing the problem.

I tried to simply log a variable to the console and it works now, but the value is quite different from the declaration. I have a movementSpeed variable of 5.0f, but it gets logged out as some random very high integer. When I build the solution, I get the following warnings:
"non-portable use of class 'ComponentVariableFloat' as an argument to a variadic function" (I'm using "Log::message("The movement speed is %d", movementSpeed);"
"declaration of 'node' hides class member" (This one has its origin in the ComponentSystem.h file)

What is going on here? Do I have to access the variable via the property file?

Thanks again!

Edited by christine.donath
Link to comment

Hi Christine,

maybe just a typo, but can you change Log::message("The movement speed is %f", movementSpeed);" This should fix your problem. (Your actual float-value should be untouched).

Edited by christian.wolf2
Link to comment

Hi Christian,

thank you for your suggestion! It was indeed a typo and I feel a bit stupid now, haha. It worked partially as it stopped showing a random int and instead showed a 0.0000. I had to type "movementSpeed.get()" for it to work and to stop throwing the first warning.

Edited by christine.donath
  • Like 1
Link to comment

Good, happens sometimes to me too! :)

But normally you don't need to call movementSpeed.get() in order to get the things working. Can you maybe share how you have implemented the properties/component variable in your project?

  • Like 1
Link to comment

I have declared the parameter in the header file (TestBall.h), with or without an initial value:

PROP_PARAM(Float, movementSpeed, 15.0f);

and then I log it within init() or update() like this (TestBall.cpp):

Log::message("My movement speed is %f", movementSpeed.get());

 

Link to comment

Okay, but nothing else? Than that is only half the deal. You now have two options:

1. Create a new property-file, for example name it "mover.prop". In those file, add the following lines of code:

<?xml version="1.0" encoding="utf-8"?>
<property version="2.7.3.0" name="mover" manual="1" parent_name="node_base">
	<parameter name="movementSpeed" type="float">4.5</parameter>
</property>

The parameter name should be the same, as his name in the header file. In your editor project, click on the test-ball and on the right, click "Add New Property" and attach your previously generated mover.prop to it. In your TestBall.h add the line

static const char* getPropertyName() { return "mover"; }

And don't forget to add in your source file "REGISTER_COMPONENT(TestBall);" after including headers. Before running your application, Unigine will look into the loaded world, which nodes/surfaces/materials have an property assigned and which component (if enabled) are valid for it. Than, it will automatically call the proper class with all your defined functions.

2. Attach your property-files via code. Instead of attaching the property files at the editor, you can add them either via

NodePtr ballNode;

//get your ball node from editor.
...

//add it via 
ComponentSystem::get()->addComponent<TestBall>(ballNode);

 

or

NodePtr ballNode;

//get your ball node from editor.
...

//add it via 
obj[2]->addProperty("mover");

Make sure, in your second case, that the given name is the same property name, es declared in your header-file via getPropertyName().

Link to comment

Sorry for double-checking: The property file is generated automatically with my code (I thought that was a new thing with the Custom Component System so you don't have to do everything manually), so I'm not sure what this approach will change exactly. I can see the property file in the editor and I can attach it and manipulate the values. The strange thing seems to be the Log class. At all the other places I used the variable movementSpeed, I could just insert it as is without the get() - like actually moving the ball with the press of a button.

Thank you for taking the time to help me though :) Much appreciated.

Link to comment
  • 3 years later...

I'm also having similar issue with the component system.
After creating the components, only one of them is visible as a .prop file within the editor. Where are the rest? Do I need to do something special to generate them?

Link to comment

You need to build and run your application from IDE in order to generate prop files from C++ component system.

Please check this tutorial on how to start with C++ Component System: https://developer.unigine.com/en/docs/latest/start/quick_start/character/index?rlang=cpp#controls

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...