StaticMeshComponenet Transforms nullptr, Access violation?

I’m pretty sure you can still get the component transform even if there’s no mesh set.

1 Like

BP
why I am able to do it with just a pure blueprint class, and everything works, the mesh is empty but it has just the transforms , when I get it and read I get location values of the container in world transform and not returning null.

C++
I am not setting the mesh at this point I get the nullptr but I am getting the world transforms of the container already setted up in the container

I did not even know you can have a static mesh component without a mesh.
Might be one of the causes it gives null.
The location missing is actually really the indicating factor that she has no location on the component, there is no line mentioning location factors.

She has a transform function but on what location >?

this is the main problem, in blueprint I can get it and in C++ can’t.

Can you add this before accessing the transform to see if the crash is because of StaticMesh01 being null.

if(StaticMesh01 != nullptr)
{

 }
1 Like

The root component is overriden by scene component , so now the root component is scene component

Stop tranforming native code bp to C++ it’s not going to help you in the future, learn to do things without BP.

I will help you out just this one time :slight_smile: since this is like beginer stuff.

it returns the static mesh is nulled , already tried it

Can you try accessing the component from BP and check if it’s valid ? Also do you have any code that might destroy the component at runtime ?

I am not transforming bp native code , i am just getting ideas from it how the things are done behind the scene :smiley:

in the derived bp class from this C++ , returned the same nullpts.

doing the whole logic in the pure bp class returned valid transforms values

So after you follow the tutorial on that guy on how to set up correctly the mesh components then you will want to do this.

Const FVector Location_Variable = Your_Component1->GetComponentLocation();
YOu can use a ftransform instead of a vector but I don’t like Ftranssform.

Now that you have the location, you can use the location in your transform function with the line you have.

For example:
VariableRelativeLocation that you got from previous step = Function that you will use to transform ().Some other values here(Location_Variable);

So you see there are two steps first, number one get a location variable with a get location function() and second use the transform function with your location that you got.

let me try this , will update in minutes

The derived BP class shows the components are available, yet you do get null after spawning ? Try adding a test spawn in the level blueprint, spawn the derived class, then go to your outliner, select the spawned class and check if you can see the components.

Here’s an example, the rifle is spawned and I can access it while playing and see what components it has.

I found that I am already doing this dynamically

do
				{
					RandomLocation(Available, Location);
				} while (UsedLocations.ContainsByPredicate([Location](const FTransform Transform)
				{
					return Transform.GetLocation() == Location.GetLocation();
						&& Transform.GetRotation() == Location.GetRotation()
						&& Transform.GetScale3D() == Location.GetScale3D();
				}));

yes, I have doubts on runtime issues, something is access early before the time

Where in your blue prints, poitless if you don’t have a blue print class to extend to your other c++ class as an aditional component.
This is a blue print class library.

Best you can do is look at the tutorial I gave you from youtube and only extend variables and other stuff towards Blue prints, not vice versa, because for that you need a blue print library class.

1 Like

and instead of spawning objects in the level, when I print what is going on behind the scene, I found that everything works fine , as we can see all groups has random items and every item has its own random location.
so this random location is set dynamically as a spawn location for mesh and the world transforms is just for avoiding overlapping meshes when spawned in a group.
in my case I have 5 of them with different world transforms because they will be placed in the level .

StaticMesh01->USceneComponent::GetComponentTransform();

Mmm this is also bad, why are you using the scene component to transform, use the component, not the root component.

The root component is just the capsule holding everything.
If you want you can get location on actor, but you will not be able to transform individual items on the actor and their relative offset to world, neither will the component will do this, you have to get mesh relative location and their offsets on the component.

First you can try to use this function.
Just get actor location
GetActorTransform()
You can use it with “.” to get additional parameters on the function.

GetActorTransform.Whatever you want added.

Here is a complete sintax:
For example.

const FVector Location = Component->GetComponentLocation();

Const FVector WorldLocationVar = GetTransform().TransformPosition(Location);

This is like a give away from me it will transform to world posssition.

A good practice is first always transform to relative possition so there is additional code if you want everything to work. But I don’t post whole pages of code, it’s better to discover on your own.
So first you have to go “inverse” and transform to local relative space to get local relative location on objects and then transform back. Oherwise you are going to get error locations that are offsets that are distorted.

2 Likes