How would i get acces to a object that i only know the name of?

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

2 Comments

How is this thing created/instantiated? Does it not have a 'Tag' property that can be used to identify?
When i create a geometric object inside the app, a SceneManager object is created with it. This scenemanager can create objects that inherit from Movcomp and these are saved directly to a list in the SceneManager object.
I couldnt find a tag property, so i instead just call a event inside of movcomp that sends the scenemanager object with it.
%SceneManager
SceneManager.CompCount=SceneManager.CompCount+1;
NewComp=MovComp();
notify(NewComp,'CreationParent',SceneManager);
SceneManager.List(SceneManager.CompCount)=NewComp;
%MovComp
%setup
addlistener(Movcomp,'CreationParent',@Movcomp.ConnectParent);
%ConnectParent
function ConnectParent(src)
Movcomp.SM=src;
end
Now, its taking forever to configure my customcomponent using Command window. So i am wondering what could have gone wrong? Has it something to do with my Classes not being configured before using them as variables, i am not sure if having them in the same folder is enough for the compiler to recognize that my variable list be of type Movcomp?
%Configure line in Commandwindow
appdesigner.customcomponent.configureMetaData('TNA002\SceneManager.m')

Sign in to comment.

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

@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...
@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.
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., ...
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.
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.
I reported it to the advisory board.
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.

Sign in to comment.

Categories

Products

Release

R2025b

Asked:

on 7 Feb 2026

Edited:

on 10 Feb 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!