Getting Access to the Canvas

OK, so I am at a loss on this. So I’ve set up a player with a ray cast which initiates a script event when the raycast hits an entity with an ‘item’ tag. It only does this once and then triggers a boolean to turn false when it’s not hitting anything like that. This is all working just fine.

The issue is that when the script event fires I’m trying to get access to a canvas which is associated with an entity. I’ve loaded it automatically. Then I use Get Canvas node and get a reference to that from an entity variable which points to the entity with the loaded canvas.

But I try to iterate through the children and I’m not getting any names when I try to use Get Name node and print it out. So I’m not getting access to this canvas and I can’t figure out what’s going on.

The bottom print works. It prints out true and false when it’s supposed to. But I can’t get access to the canvas.

Hey Wcb,

Three things I would check here:

  1. That the Get hud node is actually being set to an entity. Does it have your player or hud entity as the value in the variable manager? Add a print node to print the EntityId value after GetHud (it should look normal, i think it does spit out a dummy entityId value if it isn’t set)

  2. That the entity with the canvas had enough time to load the canvas before you are asked for a reference to it. You might just avoid this problem by leaving the canvas unloaded and calling the load canvas node in this script you have posted. Otherwise I see that there is a ‘On Canvas Loaded Into Entity’ node that you can use to be sure the canvas ready to reference. The node should either fire immediately on connecting if the canvas is already loaded and ready or it will fire at some point after when it is ready.

  3. If that reference to the canvas is all good, ensure that the canvas actually has child UI elements. Perhaps add a print node right after ‘For Each’ and see how many times it fires and that the EntityIds are all unique and match the count you would expect.

I decided to just do this

I made a script canvas just for the entity with the canvas and attached the script canvas to it. This doesn’t have any output at all. It doesn’t print a thing. The UI Canvas has children.

It won’t even spark that event.

The canvas loads fine but it doesn’t seem to be loading into the entity. I know the canvas loads because I can see the GUI.

Not even that works. I meant “HUD LOADED INTO ENTITY” ftr

@wcb

Another thing to check is that the UI component is on the same entity you are referencing in the ‘GetHud’ node. If, in your level layout, your top-level ‘Player’ entity has the UI component and you are referencing ‘Player’ in GetHud, that all sounds fine. If your Player entity has a child entity called Hud or something, and the child actually the entity with the UI component, then the child component needs to be the referenced EntityId in GetHud.

Here is an older forum post with a two-part tutorial on working with the UI in scriptcanvas, it has the scriptcanvas graph there too, the layout is probably jumbled, it’s from an older version of Lumberyard. The tutorial doesn’t cover cross-entity referencing, but plenty on wrangling UI canvases with some of the caveats of referencing them.

1 Like

If I do this then I can get HUD LOADED INTO CANVAS print statement to work. But it still doesn’t print children.

For that graph to work, it would have to be on the entity with the UI component, because the source is set to self.

If this graph is on a different entity you’ll need to change the source.

The graph (“hud.scriptcanvas”) is now connected to an entity called “hud” which has a canvas ref attached called “hud” which is hud.uicanvas that has children.

I did that to attempt to isolate what the problem is. I have no idea why I can’t get access to the children in hud.uicanvas which is attached to entity “hud” which has the above graph in it which is a scriptcanvas “hud.scriptcanvas” It will not print out any of the children.

This is what I currently have. And I can get this “(Script Canvas) - HUD LOADED INTO ENTITY: [706703339973959]” but that’s all I get.

I should get all the children but I do not. I have no idea how to know if that big long number is a “dummy” number or not.

OK that sounds like a good setup to work from. That EntityId looks fine.

I also tried a different uicanvas file just to see if the hud one is corrupted. It doesn’t work with either uicanvas file. Can’t print out children.

I see one issue…the Get Children node. Is UI Element Get Children, not UI Canvas Get Children.

2 Likes

Those nodes that have the same name but slightly different categories get me plenty.

1 Like

DOH! all I did was search “get children” and assumed since it was UI it was appropriate. That fixed it. THANK YOU!

You got it! That tutorial might still be worth a look for the caveats…there is another category, UI Canvas Manager that can be useful but you have to mind the pathname, that’s covered in one of those pdfs.