Hi there, I apologize if I’m getting something wrong or missing something obvious, I’ve just running into an extremely strange error and am a junior programmer.
I’m using C++ to create a game wherein a need a player and an arm as separate objects. They are both custom C++ classes. I didn’t originally intend to make the arm its own thing, but thats what seemed to work.
I’ve been running into a lot of issues with it but the most confounding one so far is an access error at 0x0…04xb0, which I know translates to 1200. It happens when I try to access a variable or a function held by the arm object. What’s interesting to me is when I hover over the variable type definition, it says its size is also 1200. Is there any way this thing is reading the size as the address?
I’m using Unreal 5.4.4 and Jetbrains Rider for my IDE. I’ve attached some screenshots as well. Any help would be extremely appreciated!!
You can’t do GetDefaultSubobjectByName in the constructor (AcrabController). It won’t exist at that time.
You have a few options:
Option 1: Do another CreateDefaultSubobject to make the arm in the constructor. You can then edit that component in blueprint if you want.
If you have to create it in blueprint:
Option 2: in BeginPlay you can cache the arm component into your member variable like you’re trying to do there (but using the “normal” Get or Find Component functions, not GetDefaultSubobject)
Option 3: don’t cache and just get it inside each of the functions that wants to do thing to it.
Hi, thank you so much for your help, I wouldn’t have realized that on my own unless I just experimentated for a long while, lol. However I’m still having some issues.
Creating the subobject proved difficult as it wasn’t showing in the blueprint and I was really unsure of how to attach it to the root component. So I’m trying option 2 by experimenting with both finding the component by tag and by class. When I do it by class, I get this error:
error C2338: static_assert failed: ‘‘T’ template parameter to FindComponentByClass must be derived from UActorComponent’ (with T = AtheArm)
Getting it by tag causes the same errors as before. I added the tag, named “armComp”, under component tags for the arm object in the blueprint editor.
I know it’s probably something to do with the syntax, but I can’t find clear documentation on what that syntax should be. Could you please help?
Hey, I was slightly mistaken about if it was actually working or not.
From what I understand, your modification should’ve made create subobject work and have it appear in the blueprint editor. Unfortunately although it does successfully create an arm during runtime (it appears in the item list under outliner), it still does not appear in the editor, where I need to place and resize it.
Is it something to do with an attachment method maybe? I can’t use what I used for camera since they’re different types, so I tried
ourArm->AttachToActor(this, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true));
I’ve also tried using RootComponent instead of this as a parameter. What am I missing?