Should I use 5.3 instead of 5.4?

#1
Hello,

Is C# programming better in 5.3? It feels like 5.4 was done poorly. The API for 5.4 is missing most of the classes, or the search bar doesn't work or both. The UI tutorials on the wiki are for 5.3 and don't work in 5.4. ((Text rendering, buttons, etc.) drawing rectangles work) (Text rendering simply doesn't work.)
I chose C# because it's easier to use than C++. Is C++ more popular and so support for C# is lacking due to the focus being C++? Should I use C++?

I just find it weird that the most basic of tasks don't work very well. Even the Menu tutorial for 5.3 seems backwards to me, and maybe that's due to a limited use of object oriented programming on my part. I think most of the code could be simplified into one or two classes. The benefit is that it's a lot easier to read and understand. Although, I guess arguably it wouldn't be as easy to expand upon later.

I wouldn't complain, and I would just say "I suck, and don't know what I'm doing". But when I read posts like this one from a year ago I start thinking "I'm not crazy?"
https://www.cryengine.com/community_arc ... 5&t=134149

For instance, this is the code for drawing text. Very simple and straight forward. Similar to how I created UI in Java. I get a crash whenever I try to run this.
There's something wrong with "var can = SceneObject.Instantiate<UIElement>(this);" and maybe the line below but without an updated API it makes it very difficult to figure out whats wrong.
I don't want to deal with ActionScript cause I just want a very simple and basic UI.
I've tried exchanging UIElement for Canvas and Panel. Tried switching out "this" with SceneManager.RootObject and "null".

Code: Select all

   class UIHomeMenu : UIElement
   {
      public event Action StartPressed;
      public event Action QuitToDesktopPressed;
    //   private UIButtonList _mainMenuButtons;
    //   private UIButtonList _text;
      
      public override void OnAwake()
      {
      //Code for working rectangle was here
      //create text below.
   var can = SceneObject.Instantiate<UIElement>(this); //
       var text = can.AddComponent<Text>();
   text.Alignment = Alignment.Center;
       text.Height = 24;
       text.Content = "text";
       text.Offset = new Point(0f, 0f);


I hope it doesn't sound like I'm just trying to bash. Heh, pun? The forums are extremely helpful and many people helped me out with the last post I made and I'm grateful for that. It's just frustrating that such a menial task has no documentation and doesn't work.
Is there a better documented version that I should switch to?

Re: Should I use 5.3 instead of 5.4?

#4
mknmknmknjk wrote:the doc is for ce5.3
check template source code.

From the last thread I made, this guy claimed the doc was not up to date. The buttons/text in the menu doc compile, but crash immediately. So the doc is incomplete or outdated. And the UI object is not in the API.
The doc is pretty clear and straight forward.

Re: Should I use 5.3 instead of 5.4?

#5
If I Destroy the text, the program runs without crashing. It doesn't make sense that improper garbage cleanup is the problem though. Cause my main class has _canvas.Destroy() under the Dispose() method.
And if I comment out the following section of code the game runs.

Code: Select all

         can = SceneObject.Instantiate<Canvas>(SceneManager.RootObject);
          text = can.AddComponent<Text>();
         text.Alignment = Alignment.Center;
          text.Height = 28;
          text.Content = "text";
          text.Offset = new Point(10f, 10f);
          text.Destroy();
          

Re: Should I use 5.3 instead of 5.4?

#8
cry-miron wrote:Are you perhaps also loading a map while creating the menu? It's possible that there's a conflict with the UI trying to create textures, and the engine cleaning up all the textures while the level is loading.

Sure am. Thanks for your help. Compiles & runs now. In the doc it looks like the menu is created after loading a level. If I want a similar effect I would need to create an EventHandler and listen to the class "LevelSystem" and create the UI after the level is loaded correct? I've created the following code like so, but something isn't quite right.

Code: Select all

      private Game()
      {
... .... ....
         if(!Engine.IsSandbox)
         {
            Engine.Console.ExecuteString("map Menu", false, true);
            LevelSystem.LoadingComplete += new EventHandler(OnMenuLoaded);  //Redundant explicit delegate declaration
         }
      }
        private void OnMenuLoaded(object sender, CryEngine.EventArgs e)  //When I used ", EventArgs e" it said it was the wrong type.
        {
        //If (e.level = "menu") { //   <-- Theoretically.
            _canvas = SceneObject.Instantiate<Canvas>(null);
      _mainMenu = new MainMenu(_canvas);
        }

Re: Should I use 5.3 instead of 5.4?

#10
Sweet. Static Methods can't call non-static methods. And it seems like initializing methods isn't a thing. Do I need to put CreateMenu() in a separate class?
Also, interestingly enough, it seems if you put a delay of maybe ~100 milliseconds or something, a map can load and the UI will continue working. So the new map garbage cleanup must be pretty quick. So possibly it isn't necessary to wait for OnLevelLoaded. I'm fine with it working this way. (I put a timer on a transparent rectangle that fills the screen to fade in/out. (Basic intro credits screen))

Also button.Ctrl.Text.FontStyle = System.Drawing.FontStyle.Bold;
I had to add System.Drawing to the references. Simple enough. It crashes with no error though. Weird... Works now! Maybe Xamarin had to be restarted after adding a reference...

Code: Select all


{
   public class Game : IDisposable
   {
      private static Game _instance;
      private Canvas _canvas;
      private MainMenu _mainMenu;

      private Game()
      {
      ... ... ... ...
      public static void OnLevelLoaded()
      {
         CreateMenu();//Can't call non-static method
      }
      private void CreateMenu()
      {
         _canvas = SceneObject.Instantiate<Canvas>(null);
         _mainMenu = new MainMenu(_canvas);
      }

Who is online

Users browsing this forum: No registered users and 1 guest