This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Hi, I have a bunch of hex tiles instantiated on world generation

        for(...)
                    Spatial p = (Spatial)LandHex.Instance();
                    p.Translate(new Vector3(x, y, z));
                    AddChild(p);

and so far all good. Then through a button I try to instantiate a scene with a couple of models, pretty standard stuff I imagine:

public void _on_ButtonFarm_button_up()
{
    GD.Print("Farm loaded");
    if(Hexagon.selectedHex != null)
    {
        Spatial p = (Spatial)Farm.Instance();
        Hexagon.selectedHex.AddChild(p);
    }
}

Now, the farm doesn't show up here, but if instead of hexagon.selectedHex.AddChild(p) I just do AddChild(p), which will bind it to the button itself, it appears just fine. I have also attempted to Translate() it, Scale() it etc, just in case. Inspection in the editor with Remote does not show anything abnormal, all transforms etc have non-zero values.

Any ideas?

I have also tried doing .setVisible(false) on the tiles to make sure they're not hiding it, and .setVisible(true) in case it inherits the visibility, but the child is nowhere to be seen.

The nodes:
Hexagon:

KinematicBody
    hexagon (Spatial)
        StaticBody (model with attached Hexagon.cs script)
            CollisionShape

Farm:

Spatial
    Spatial (with the actual model)

When I run it and switch to Remote, I see the farm attached under the StaticBody, which I expect since that's where the Hexagon class lives

Godot version 3.5.1 stable
in Engine by (20 points)
edited by

If the farm is a child of the tile and you hide the tile the farm will be hidden. Also what kind of node is the farm? Is it 2d or 3d, if it's 2d it will take some extra work to make it show up in 3d. The main problem is that although you've explained what you've tried and the basic instantiation code you haven't shown what the actual nodes are.

Sorry I'm still figuring it out, I'm not used to the nodes behaving differently between 2D and 3D.
I updated the post with the nodes, the farm becomes a child of the node with the model, as that's where the Hexagon.cd script is attached (which I assume is the right place since it's the most direct place to make the hexagon oscillate when it is selected). Everything is 3D.
Also the inherited hiding I (tried to) counter by explicitly setting the farm as visible, which again works when I add it as a child of the button but not of the tile.

Try seeing if the farm shows up correctly when it is not a child of the hex. Also make sure that if you're moving the farm, not to move it relative to the world origin as that will through off you're calculations; When the farm is a child of the hex the hex's position is Vector3(0,0,0) as far as the farm is concerned.

You gave me an idea and were on kind of on point: I set the world coordinates of the farm, that worked so I checked the coordinates on the entire hierarchy above. I had a rogue scaling in a node above the hex, which did not affect the hex because it's relative position to that node was (0,0,0), but apparently affected the farm because it had an offset, so that offset was scaling up. In hindsight that scaling was also not done properly, but at the time I hardly knew anything about the engine, but there's still something that doesn't add up in how the farm was affected (it flew off diagonally instead of vertically, and didn't scale back down along with the selected hex which is pulsating). Now that I rectified the way I do the pulsation, it works properly. Thank you very much for pointing me in the right direction

TL;DR for anyone looking at this later: the entire hierarchy above will affect the position, including any scaling done. Try recursively printing all the parent nodes' transforms to see if something is off.

Put this in the answer so this post no longer shows as unanswered.

Done, thanks again!

1 Answer

0 votes
Best answer

(Thanks to Merlin1846 for a push in the right direction) I had a rogue scaling in a node above the hex, which did not affect the hex because it's relative position to that node was (0,0,0), but apparently affected the farm because it had an offset, so that offset was scaling up. In hindsight that scaling was also not done properly, but at the time I hardly knew anything about the engine, but there's still something that doesn't add up in how the farm was affected (it flew off diagonally instead of vertically, and didn't scale back down along with the selected hex which is pulsating). Now that I rectified the way I do the pulsation, it works properly. Thank you very much for pointing me in the right direction

TL;DR for anyone looking at this later: the entire hierarchy above will affect the position, including any scaling done. Try recursively printing all the parent nodes' transforms to see if something is off.

by (20 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.