Getting Access to the Canvas

0

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.

REMOVEDUPLOAD

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

asked 4 years ago216 views
14 Answers
0
Accepted Answer

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

answered 4 years ago
0

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.

answered 4 years ago
0

I decided to just do this

REMOVEDUPLOAD

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.

answered 4 years ago
0

REMOVEDUPLOAD

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

answered 4 years ago
0

@REDACTEDUSER

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.

https://forums.awsgametech.com/t/creating-a-main-menu-with-script-canvas/5619/6

answered 4 years ago
0

REMOVEDUPLOAD

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

answered 4 years ago
0

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.

answered 4 years ago
0

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.

answered 4 years ago
0

REMOVEDUPLOAD

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.

answered 4 years ago
0

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

answered 4 years ago
0

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.

answered 4 years ago
0

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

answered 4 years ago
0

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

answered 4 years ago
0

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.

answered 4 years ago

This post is closed: Adding new answers, comments, and votes is disabled.