How would i get acces to a object that i only know the name of?
Show older comments
I have this custom component that i want to make for the app designer, the issue is that i am unable to send the object in question to the custom component on creation as that isnt allowed.
This code snippet was something i tried but didnt work as its not allowed to have custom components with input parameters.
function obj = Movcomp(Scenemanager)
addlisterner(Scenemanager,'Delete',@Movcomp.Delete)
end
i would still like to do something like this As the Scenemanager will be one or multilple objects that will create and delete different components using callbacks. I couldnt find a way to create global callbacks similair to what can be done using a singleton for signals in godot
Answers (1)
Hello,
I saw your post about the custom component issues in App Designer. I dug through the MathWorks docs and found what's going on. Good news is both problems you're hitting have pretty straightforward fixes.
So here's the deal - you've got two issues:
1. You can't pass SceneManager as an argument when creating MovComp
2. configureMetadata is hanging forever
THE CONSTRUCTOR PROBLEM
The reason you can't do this:
function obj = Movcomp(Scenemanager)
addlistener(Scenemanager,'Delete',@Movcomp.Delete)
end
...is that App Designer has a hard rule: the setup method can't have required input arguments. Period. It's not a bug or limitation you can work around - it's just how custom components work in App Designer.
But honestly, there's a simpler way to do what you want anyway. Instead of passing SceneManager through the constructor, just set it as a property after you create the object. Here's how:
1. Fix your MovComp class:
classdef MovComp < matlab.ui.componentcontainer.ComponentContainer
properties (Access = public)
SceneManager % Set this after creation
end
properties (Access = private)
Initialized (1,1) logical = false
end
methods (Access = protected)
function setup(obj)
% No arguments allowed here!
obj.Position = [100 100 200 50];
% Create your UI stuff
end
function update(obj)
% This automatically runs when properties change
if ~obj.Initialized && ~isempty(obj.SceneManager)
% Now you can use SceneManager
addlistener(obj.SceneManager, 'Delete', @obj.handleDelete);
obj.Initialized = true;
end
end
end
methods (Access = private)
function handleDelete(obj, src, event)
% Your delete handler
end
end
end
2. Fix your SceneManager class:
The hanging issue is almost certainly because your List property isn't typed properly. You need to give it a type AND a default value:
classdef SceneManager < handle
properties
CompCount (1,1) double = 0
List (:,1) MovComp = MovComp.empty(0,1) % This is important!
end
% rest of your code...
end
When configureMetadata can't figure out what type a property is, it just hangs trying to parse your class. This should fix it.
3. Create components the simple way:
Forget the whole event notification thing. Just do this:
SceneManager.CompCount = SceneManager.CompCount + 1;
NewComp = MovComp(); % No arguments
NewComp.SceneManager = SceneManager; % Just set it directly
SceneManager.List(SceneManager.CompCount) = NewComp;
That's it. When you set the SceneManager property, the update() method runs automatically and sets up your listener. Much simpler than the event approach you were trying.
4. Fix the hanging configureMetadata:
Before you run configureMetadata again:
a) Check for syntax errors:
checkcode('TNA002\SceneManager.m')
checkcode('TNA002\MovComp.m')
b) Add the folder to MATLAB's path (this is critical!):
addpath('TNA002')
savepath
Just having the files in the same folder isn't enough - the folder needs to be on the path.
c) Now try configuring:
appdesigner.customcomponent.configureMetadata('TNA002\SceneManager.m')
The ComponentContainer class is designed to have properties set after creation. The update() method runs automatically whenever any property changes, so you get your callback behavior without needing to set up events manually. It's actually simpler than what you were trying to do.
Your event-based workaround with notify(NewComp,'CreationParent',SceneManager) was creative, but you were basically reinventing something that's already built into the class.
Give this a shot and let me know if it works. Should fix both the constructor issue and the hanging.
9 Comments
dpb
on 9 Feb 2026
@Umar -- not sure what you're using as your portal, but your postings lack legible formatting. @Walter Roberson and I have reformatted a number, but it would be agoodthing™ if you could manage...
Umar
on 9 Feb 2026
@dpb, your help is much appreciated. Also, appreciate help of other contributors as well as @Walter. Last year, I had no issues when posting comments, also noticed this issue. Please see attached. Any tips would be highly appreciated.
dpb
on 9 Feb 2026
I dunno anything about mobile apps/online; all I know is using a conventional browser (Firefox) and the defined keystokes Ctrl-M, Ctrl-I, Ctrl-E, etc., ...
Walter Roberson
on 9 Feb 2026
It appears as if when content is entered from mobile browser, that all formatting is lost and it is just jammed together. The previously active legacy formatting appears to be gone, and the formatting implied by the tool ribbon is ineffective.
dpb
on 9 Feb 2026
That would look like a support ticket item for Mathworks Answers support folks, then, wouldn't it? Not sure who's the right one there. But certainly that's what the symptoms appear as.
Walter Roberson
on 9 Feb 2026
I reported it to the advisory board.
dpb
on 9 Feb 2026
<thumbsup>
Walter Roberson
on 10 Feb 2026
In the meantime, @Umar most browsers for mobile phone have a configuration along the lines of "Use Desktop" . When activated, the web pages you get are full desktop functionality.
You are right about and this is exactly what is happening @Walter as you mentioned, “It appears as if when content is entered from mobile browser, that all formatting is lost and it is just jammed together. The previously active legacy formatting appears to be gone, and the formatting implied by the tool ribbon is ineffective.”
Thanks everyone for your input on this issue.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!